问题
I want to drop something not on the whole ListBox, but on a specific ListBoxItem. I'm handling the ListBox' Drop event - how can I find out, on which item the mouse is pointing?
回答1:
if (e.Data.GetDataPresent(typeof(Songs)))
{
var result = VisualTreeHelper.HitTest(myCanvas, Mouse.GetPosition(this.Playlists));
}
If using a canvas, try performing your hittest relative to the Canvas (replace "myCanvas" with the reference)
回答2:
I managed to solve this now by setting AllowDrop and the Drop event handler not on the ListBox but to the control in the ItemTemplate.
回答3:
You can use VisualTreeHelper.HitTest to figure out which ListViewItem is at the given point. That said, there may well be an easier way to do what you require, but there's not really enough info to go on.
来源:https://stackoverflow.com/questions/1596797/wpf-drag-drop-on-listbox-item