不允许在 VS2010 扩展中的 WPF 工具窗口内拖放
我这里有一个奇怪的问题。我使用带有工具窗口的 Visual Studio 集成包/VSIX 项目向导创建了一个简单的插件。在该窗口中,我想从列表框中进行简单的拖/放操作,然后将其放在同一窗口中。我在普通的 WPF 程序中做了同样的事情,但是当我在 WS 工具窗口中执行此操作时,这是不允许的。我开始拖/放操作(由 PreviewMouseLeftButtonDown
事件启动)并调用 DragDrop.DoDragDrop()
方法,我立即获得停止标志光标。不允许拖拽。
有什么想法吗?我猜是安全限制或这些 WPF 控件托管在 ToolWindowPane 和旧的 Visual Studio IDE COM 内容中这一事实的影响...感谢您的帮助!
I have a strange problem here. I've created a simple plugin using the wizard for a Visual Studio Integration Package / VSIX project with a tool window. Within that window I want to do a simple drag/drop from a listbox and drop within the same window. I've done the same thing in a normal WPF program, but when I do this in a WS toolwindow it's not allowed. I start the drag/drop operation (initiated by a PreviewMouseLeftButtonDown
event) and call the DragDrop.DoDragDrop()
method, I get the stop-sign-cursor at once. No dragging allowed.
Any ideas? Security restrictions or an effect of the fact that these WPF controls are hosted inside a ToolWindowPane and old Visual Studio IDE COM stuff I guess... Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Microsoft 的 Alin Constantin 在这里帮助了我,甚至还写了一篇关于如何在 VS2010 中正确进行拖放的博客文章!
http://alinconstantin.blogspot。 com/2010/02/drag-and-drop-in-visual-studio-2010.html
突出显示,以防链接失效:
在工具窗口(UserControl)中,覆盖
OnDragEnter
、OnDragOver
(重要!)和OnDrop
。未能覆盖OnDragOver
将导致拖/放失败。在
OnDragEnter
中,执行以下操作:DragEventArgs.Handled
设置为true
和DragEventArgs.Effects
为适当的值base.OnDragEnter()
在
OnDragOver
中,您必须执行与相同的操作 >OnDragEnter
。如果您未能设置Handled
,Visual Studio 将接管并且您将无法处理放置!在
OnDrop
中,DragEventArgs.Handled
设置为true
base.OnDrop()
记住,不是处理
OnDragOver
将导致 Visual Studio 接管拖动操作,从而使您无法在OnDrop
中处理它。Alin Constantin at Microsoft helped me out here and has even written a blog post on how to do drag/drop within VS2010 properly!
http://alinconstantin.blogspot.com/2010/02/drag-and-drop-in-visual-studio-2010.html
Highlights, in case of link rot:
In your tool window (the UserControl), override
OnDragEnter
,OnDragOver
(important!) andOnDrop
. Failure to overrideOnDragOver
will cause drag/drop to fail.In
OnDragEnter
, do the following:DragEventArgs.Handled
totrue
andDragEventArgs.Effects
to the appropriate valuebase.OnDragEnter()
In
OnDragOver
, you must do the same thing asOnDragEnter
. If you fail to setHandled
, Visual Studio will take over and you won't be able to handle the drop!In
OnDrop
,DragEventArgs.Handled
totrue
base.OnDrop()
Remember, not handling
OnDragOver
will result in Visual Studio taking over the drag operation, denying you the ability to handle it inOnDrop
.