我怎样才能从(X,Y)位置的ListView项? [英] How can I get an ListView item from the (X,Y) position?
本文介绍了我怎样才能从(X,Y)位置的ListView项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在WPF一个ListView下降东西。我需要知道我丢弃(X,Y)的位置的项目。我怎样才能做到这一点?
I am dropping something in a ListView in WPF. I need to know the item in the (X,Y) position I am dropping. How can I do this?
在WPF ListView控件没有话getItemAt。我回到我原来的问题。
The WPF ListView doesn't have GetItemAt. I return to my original problem.
推荐答案
完成!由于这篇文章
<一href=\"http://www.$c$cproject.com/KB/WPF/WPF_Drag_And_Drop_Sample.aspx\">http://www.$c$cproject.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;
}
这篇关于我怎样才能从(X,Y)位置的ListView项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文