1

我有以下内容:

Window window = Application.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
ScatterView main = UIHelper.FindChild<ScatterView>(window, "MainScatterView");
        main.Items.Add(type);

//Neither of these work
ScatterViewItem parent = (ScatterViewItem)main.ContainerFromElement(type);

ScatterViewItem parent = UIHelper.FindVisualParent<ScatterViewItem>(type);

文档说:当您添加不是 ScatterViewItem 类型的对象时,ScatterView 控件首先将对象包装在 ScatterViewItem 控件中,然后再将其添加到集合 http://msdn.microsoft.com/en-us/library/microsoft .surface.presentation.controls.scatterviewitem.aspx

如何获得包裹在其中的 scatterviewitem?

4

1 回答 1

2

与其他所有ItemsControl一样,ScatterView 通过ItemContainerGenerator创建和管理其项目容器,它提供了获取某个项目的容器或获取某个容器的项目的方法:

ScatterView scatterView = ...
object item = ...
ScatterViewItem scatterViewItem =
    scatterView.ItemContainerGenerator.ContainerFromItem(item) as ScatterViewItem;

或者

ScatterViewItem scatterViewItem = ...
object item = scatterView.ItemContainerGenerator.ItemFromContainer(scatterViewItem);
于 2012-11-07T22:42:12.243 回答