John Sourcer
John Sourcer

Reputation: 451

Removing ScatterViewItems of type other

I add a ScatterViewItem dynamically as so, noting that I am not creating a ScatterViewItem specifically as they should be wrapped in one when added as per the docs:

VideosProducts videosProducts = VideosProducts.GetVideoProductsControl();
videosProducts.Name = "VideosProducts";
main.Items.Add(videosProducts);
ScatterViewItem item = main.ItemContainerGenerator.ContainerFromItem(videosProducts) as ScatterViewItem;
item.ApplyTemplate();
item.Background = new SolidColorBrush(Colors.Transparent);
item.ShowsActivationEffects = false;
item.Center = new Point(430, 820);
SurfaceShadowChrome ssc = item.Template.FindName("shadow", item) as SurfaceShadowChrome;
ssc.Visibility = Visibility.Hidden;

But now when I try to remove them as follows:

Window window = Application.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
ScatterView main = UIHelper.FindChild<ScatterView>(window, "MainScatterView");
List<ScatterViewItem> svItems = main.Items.Cast<ScatterViewItem>().Where(svi => svi.Name != "MenuControl").ToList();

I get an invalid cast exception. What gives? I thought these items were added as ScatterViewItems?

Upvotes: 0

Views: 65

Answers (1)

Fede
Fede

Reputation: 44048

use the same ItemContainerGenerator.ContainerFromItem mechanism as in the above code for each item in the second code.

Upvotes: 1

Related Questions