不允许在VS2010扩展中的WPF ToolWindow中拖放 [英] Drag Drop Within WPF ToolWindow in VS2010 Extension Not Allowed
问题描述
我在这里有一个奇怪的问题.我使用带有工具窗口的Visual Studio集成包/VSIX项目的向导创建了一个简单的插件.在该窗口中,我想从列表框中进行简单的拖放,然后将其拖放到同一窗口中.我在普通的WPF程序中做了同样的事情,但是当我在WS工具窗口中这样做时是不允许的.我开始拖放操作(由PreviewMouseLeftButtonDown
事件启动)并调用DragDrop.DoDragDrop()
方法,我立即获得了停止信号光标.不允许拖动.
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.
有什么想法吗?安全限制或这些WPF控件托管在ToolWindowPane和旧的Visual Studio IDE COM组件内部这一事实的影响,我想...谢谢您的帮助!
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!
推荐答案
Microsoft的Alin Constantin在这里帮助了我,甚至写了一篇博客文章,介绍如何正确地在VS2010中进行拖放!
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:
在工具窗口(用户控件)中,覆盖OnDragEnter
,OnDragOver
(重要!)和OnDrop
.未能覆盖OnDragOver
会导致拖放失败.
In your tool window (the UserControl), override OnDragEnter
, OnDragOver
(important!) and OnDrop
. Failure to override OnDragOver
will cause drag/drop to fail.
在OnDragEnter
中,执行以下操作:
- 检查是否可以处理投递
- 如果是这样,请将
DragEventArgs.Handled
设置为true
并将DragEventArgs.Effects
设置为适当的值 - 致电
base.OnDragEnter()
- Check to see if you can handle the drop
- If so, set
DragEventArgs.Handled
totrue
andDragEventArgs.Effects
to the appropriate value - Call
base.OnDragEnter()
在OnDragOver
中,您必须执行与OnDragEnter
相同的操作.如果您未能设置Handled
,Visual Studio将接管并且您将无法处理删除操作!
In OnDragOver
, you must do the same thing as OnDragEnter
. If you fail to set Handled
, Visual Studio will take over and you won't be able to handle the drop!
在OnDrop
中
- 处理下落
- 将
DragEventArgs.Handled
设置为true
- 致电
base.OnDrop()
- Handle the drop
- Set
DragEventArgs.Handled
totrue
- Call
base.OnDrop()
请记住,不处理OnDragOver
将导致Visual Studio接管拖动操作,从而使您无法在OnDrop
中处理它.
Remember, not handling OnDragOver
will result in Visual Studio taking over the drag operation, denying you the ability to handle it in OnDrop
.
这篇关于不允许在VS2010扩展中的WPF ToolWindow中拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!