Reputation: 3781
I have a WPF user control that provides drag and drop functionality within that control. When the user control is hosted within a WPF app, all works fine. However when it is hosted within a VSPackage
ToolWindow
, drop is disabled altogether.
In this particular case I'm trying to drag a selected item in a draggable list box (left side of diagram below) onto a canvas on the right side.
The drag can be initiated with DoDragDrop
, such as:
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.LeftButton != MouseButtonState.Pressed)
dragStartPoint = null;
if (dragStartPoint.HasValue)
{
DragDrop.DoDragDrop(this, Content, DragDropEffects.Copy);
e.Handled = true;
}
}
But then drop is not allowed anywhere in the tool window.
What kind of conditions would prevent drag and drop within a tool window, and what settings changes are necessary to enable it?
Upvotes: 1
Views: 1197
Reputation: 3781
The answer was found in Alin Constantin's Blog, and pointed out by user Notre on MSDN. I needed to handle ALL the drag and drop related events so that the VS shell doesn't intercept them. In my case, I needed to handle the DragOver
event in the Canvas
control:
protected override void OnDragOver(DragEventArgs e)
{
base.OnDragOver(e);
e.Handled = true;
}
Upvotes: 1