如何找到Silverlight ListBoxDragDropTarget中已删除项的索引位置

如何找到Silverlight ListBoxDragDropTarget中已删除项的索引位置,silverlight,Silverlight,我有一个silverlight列表框,它包含在ListBoxDragDropTarget中。我正在听滴滴涕的滴落事件,但我不知道如何找到滴落行动的索引。i、 我想知道用户在哪个索引点将项目放入我的列表框。当我在列表框上拖动时,在UI上可以看到一条线,指示我悬停的位置,但在拖放之后,我不知道如何从拖放事件中获取拖放位置信息。给定以下Xaml: 如果您想知道用户丢弃项目的ListBoxItem,您可以使用e.GetPosition获取鼠标位置和VisualTreeHelper.FindEleme

我有一个silverlight列表框,它包含在ListBoxDragDropTarget中。我正在听滴滴涕的滴落事件,但我不知道如何找到滴落行动的索引。i、 我想知道用户在哪个索引点将项目放入我的列表框。当我在列表框上拖动时,在UI上可以看到一条线,指示我悬停的位置,但在拖放之后,我不知道如何从拖放事件中获取拖放位置信息。

给定以下Xaml:


如果您想知道用户丢弃项目的ListBoxItem,您可以使用
e.GetPosition
获取鼠标位置和
VisualTreeHelper.FindElementsInHostCoordinates
进行命中测试:

private void ListBoxDragDropTarget_Drop(对象发送方,DragEventTargets e)
{
点位置=e.GetPosition(此.ListBoxDragDropTarget);
var hits=visualtreeheloper.FindElementsInHostCoordinates(位置,this.ListBoxDragDropTarget);
ListBoxItem dropElement=hits.FirstOrDefault(i=>i是ListBoxItem)作为ListBoxItem;
if(dropElement!=null)
{
//对dropElement执行一些操作…或者如果需要索引,请使用ItemContainerGenerator
int index=this.MyListBox.ItemContainerGenerator.IndexFromContainer(dropElement);
}
}