我在WPF中的ListView中丢弃了一些东西.我需要知道我正在放弃的(X,Y)位置的项目.我怎样才能做到这一点?
WPF ListView没有GetItemAt.我回到原来的问题.
完成!感谢这篇文章 http://www.codeproject.com/KB/WPF/WPF_Drag_And_Drop_Sample.aspx
private int GetCurrentIndex(GetPositionDelegate getPosition) { int index = -1; for (int i = 0; i < clasesListView.Items.Count; ++i) { ListViewItem item = GetListViewItem(i); if (this.IsMouseOverTarget(item, getPosition)) { index = i; break; } } return index; } private bool IsMouseOverTarget(Visual target, GetPositionDelegate getPosition) { Rect bounds = VisualTreeHelper.GetDescendantBounds(target); Point mousePos = getPosition((IInputElement)target); return bounds.Contains(mousePos); } delegate Point GetPositionDelegate(IInputElement element); ListViewItem GetListViewItem(int index) { if (clasesListView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) return null; return clasesListView.ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem; }
篮球,对不起.这应该工作正常:
FrameworkElement element = (FrameworkElement)e.OriginalSource; ListViewItem lvi = (ListViewItem)listView1.ItemContainerGenerator.ContainerFromItem(element.DataContext);