2017-02-08 79 views
1

其实我们可以缩短它。我想做的事情和这个人想要做的完全一样: ListViewItem in WPF ListView通过索引而不是数据对象抓取ListViewItem对象,而不是数据对象 - Windows 10通用

他已经在WPF中完成了它,但是我在Windows 10 Universal App开发中完成了它。我试了一下,发现方法listView.ItemContainerGenerator.GetContainerForItem();

不在那里工作,因为.GetContainerForItem();不存在。

有谁知道如何在Windows 10通用应用程序开发中做到这一点?

+0

可以只使用'listview.GetContainerForItem(项目);' – Archana

+0

的ListView hasn't该方法。它有5个以get开头的方法。它们是: – omginput

+0

GetAnimationBaseValue(),GetBindingExpression(),GetHashCode()方法,的GetValue()的GetType() – omginput

回答

2

ItemsControl类包含2种方法可用于您的要求。

public DependencyObject ContainerFromIndex(System.Int32 index); 
public DependencyObject ContainerFromItem(System.Object item); 

ListViewItemsControl类派生的,因此将支持这些方法。

实施例:

ListViewItem item = listView.ContainerFromIndex(0) as ListViewItem 

ListViewItem item = listView.ContainerFromItem(item0) as ListViewItem 
+0

非常感谢!这太棒了。 – omginput

相关问题