Q:

Removing a View in Silverlight

I'm using SandRibbons from http://www.divelements.co.uk/net/controls/sandribbonsl/ and I'm trying to add a view to my contextual tab, I've successfully done this by using,
ribbon3.Items.Add(Activator.CreateInstance(viewModel.filterValue));

Although here's the problem, how do I remove the view? I tried,
ribbon3.Items.Remove(Activator.CreateInstance(viewModel.filterValue));

and
ribbon3.Items.Remove(viewModel.filterValue);

Although it doesn't seem to be working, if anyone has done anything similiar or has any input it would be greatly apperciated.
Thanks,
Jason

A:

I'll have to say I do not use Sandribbons... but from what I can see, you do not refer to the actual view in any of the remove statements you suggested. Possible solutions could be to save the position of your view after you added it:
ribbon3.Items.Add(Activator.CreateInstance(viewModel.filterValue));
var posView = ribbon3.Items.Count - 1; // do it right after you added the view
// some stuff
ribbon3.Items.RemoveAt(posView); // note that it's the RemoveAt method

or to save the view itself before adding it and keeping it as a reference:
var theView = Activator.CreateInstance(viewModel.filterValue);
ribbon3.Items.Add(theView);
// some stuff
ribbon3.Items.Remove(theView);

Of course these are only possible and probably not the most efficient solutions to your issue, but it might help you to consider how to tackle the problem in a more optimal way.

