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!
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
.