Why my WPF application has Drag & Drop disabled (even when AllowDrop is true)?

耗尽温柔 提交于 2019-12-10 12:45:04

问题


My WPF application inhibits the Drop of files from Windows Explorer, showing a Stop-sign cursor.

I've tried setting the AllowDrop property (that of the UIElement ancestor) to true on the main window and contained controls, but no luck at all, no drag-drop events are fired.

Any ideas or suggestions to find the cause?


回答1:


Solved!

The problem was that executing my app thru VisualStudio (run/debug) prevented the interop with Windows' drag & drop mechanism. Running the App as stand-alone makes it work, but cannot debug interactively.

This answer helped a lot: Visual Studio 2010 WPF Project ran in debug or relase will not allow drag and drop to any control




回答2:


In my case it was running Visual Studio as Administrator on Windows 10. The UAC prevented the drag/drop. When I ran VS without elevating drag/drop started working in debug mode.




回答3:


According to this: http://codeinreview.com/136/enabling-drag-and-drop-over-a-grid-in-wpf/ (Which I am happy to report works!)

All you need to do is add a background on the control that has to get the drop. This will enable hit testing and thus make the drop-feature work.

Note: The background can be transparent, you just have to set it.



来源:https://stackoverflow.com/questions/18029077/why-my-wpf-application-has-drag-drop-disabled-even-when-allowdrop-is-true

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