WPF - Drag & Drop on Listbox ITEM

我是研究僧i 提交于 2019-12-13 18:22:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!