0
votes

So I have drag and drop enabled for a listview but I noted that the UIelement.IsMouseOver doesn't work during a drag and drop operation.

Source: "This is because WPF blocks all mouse actions when we doing drag drop action. You can use EventTrigger with an animation to do this."

Link

However, I am very curious why the drag drop action would block mouse actions. and if that is the case, how should i be testing if the mouse is over an element during a drag and drop operation

int GetIndexOfListViewItemMouseIsOver(ListView listview)
{
  for (int i = 0; i < listview.Items.Count; ++i)
  {
    ListViewItem item = listview.ItemContainerGenerator.ContainerFromItem(listview.Items[i]) as ListViewItem;
    if (item != null && item.IsMouseOver)
    {
      return i;
    }
  }
  return -1;
}
1
Are you trying to determine the index for inserting your dropped item?Lee O.

1 Answers

3
votes

Use this method: VisualTreeHelper.HitTest. You should have the mouse location in the drag/drop event parameters (that I assume exist but are not shown). I'm not sure on the frame of reference needed for the point passed into HitTest.