0

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?

4

1 回答 1

1

ItemContainerGenerator.ContainerFromItem对第二个代码中的每个项目使用与上述代码相同的机制。

于 2012-11-20T13:23:08.350 回答