Drag Drop Within WPF ToolWindow in VS2010 Extension Not Allowed

visual-studio-2010, vsip, vsx, wpf

Solution

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!) and `OnDrop`. Failure to override `OnDragOver` will cause drag/drop to fail.

In `OnDragEnter`, do the following:

- Check to see if you can handle the drop

- If so, set `DragEventArgs.Handled` to `true` and `DragEventArgs.Effects` to the appropriate value

- Call `base.OnDragEnter()`

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!

In `OnDrop`,

- Handle the drop

- Set `DragEventArgs.Handled` to `true`

- Call `base.OnDrop()`

Remember, not handling `OnDragOver` will result in Visual Studio taking over the drag operation, denying you the ability to handle it in `OnDrop`.

Problem

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!

Original source