有没有办法ListViewItem
在ListView
s选择发生变化时获取容器.我试过用了
listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem);
从ListView
s选择更改事件但这总是返回null.我有什么想法我做错了吗?
XAML:
代码隐藏:
private void ListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { var item = e.AddedItems?.FirstOrDefault(); // edit: also get container var container = ((ListViewItem) (listView.ContainerFromItem(item))); }
请注意,listView.ItemContainerGenerator.ContainerFromItem
自Windows 8.1以来已过时.