为什么我的 WPF 应用程序禁用了拖放(即使 AllowDrop 为 true)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18029077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why my WPF application has Drag & Drop disabled (even when AllowDrop is true)?
提问by Néstor Sánchez A.
My WPF application inhibits the Drop of files from Windows Explorer, showing a Stop-sign cursor.
我的 WPF 应用程序禁止从 Windows 资源管理器中删除文件,显示一个停止符号光标。
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.
我尝试在主窗口和包含的控件上将 AllowDrop 属性(UIElement 祖先的属性)设置为 true,但根本没有运气,没有触发任何拖放事件。
Any ideas or suggestions to find the cause?
有什么想法或建议可以找到原因吗?
回答by Néstor Sánchez A.
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.
问题是通过 VisualStudio(运行/调试)执行我的应用程序阻止了与 Windows 拖放机制的互操作。将应用程序作为独立运行可使其工作,但无法进行交互调试。
This answer helped a lot: Visual Studio 2010 WPF Project ran in debug or relase will not allow drag and drop to any control
回答by stambikk
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.
就我而言,它在 Windows 10 上以管理员身份运行 Visual Studio。UAC 阻止了拖放。当我在不提升拖/放的情况下运行 VS 时,开始在调试模式下工作。
回答by aliceraunsbaek
According to this: http://codeinreview.com/136/enabling-drag-and-drop-over-a-grid-in-wpf/(Which I am happy to report works!)
根据这个:http: //codeinreview.com/136/enabling-drag-and-drop-over-a-grid-in-wpf/(我很高兴报告作品!)
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.
您需要做的就是在必须获得下拉的控件上添加背景。这将启用命中测试,从而使 drop-feature 工作。
Note: The background can be transparent, you just have to set it.
注意:背景可以是透明的,你只需要设置它。

