rodriwasabi / gong-wpf-dragdrop

Automatically exported from code.google.com/p/gong-wpf-dragdrop
0 stars 1 forks source link

Bubbling events #15

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Place a droptarget on a Grid
2. Inside the grid, place a new droptarget on a child element of the grid

Since I'm using MVVM I have a different ViewModel for the child element, thus 
also a different event handler 
for dropping an element of a different type than dropped onto the parent Grid.

What is the expected output? What do you see instead?
The grid will handle the event and the dragOver event will never trigger on the 
child

What version of the product are you using? On what operating system?
1.1 on WinXP

Please provide any additional information below.

I circumvented this by adding a new property in DragInfo called "IsNotHandled" 
(inverted to apply default 
behaviour in this case)
In the DragDrop class I changed the following code;

static void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
{ 
    ...

    e.Handled = !dropInfo.IsNotHandled; // Allows bubbling
    Scroll((DependencyObject)sender, e);
}

and

static void DropTarget_PreviewDrop(object sender, DragEventArgs e)
{
    ...

    e.Handled = !dropInfo.IsNotHandled; // Allows bubbling
}

In the handler for my Grid I've added the following code:

public void DragOver(DropInfo dropInfo)
{
    if (dropInfo.Data is ButtonLayoutViewModel || dropInfo.Data is JoystickLayoutViewModel)
    {
        dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
        dropInfo.Effects = DragDropEffects.Copy;
    }
    else
    {
        dropInfo.IsNotHandled = true; // Allows the event to bubble to the next element
    }
}

This resolved my issue of allowing drop onto a child viewmodel on a viewmodel.

Original issue reported on code.google.com by b.a.roys...@gmail.com on 21 May 2010 at 6:45

GoogleCodeExporter commented 8 years ago
I had this problem as well, my scenario:

* Dropping an object into a list adds a new item
* Dragging a list item within the list changes the order
* Dragging a list item outside to the parent container removes it from the list

Your patch worked perfectly. I have added it to my fork here 
https://github.com/rdingwall/gong-wpf-dragdrop.

Many thanks, Rich

Original comment by rdingw...@gmail.com on 18 May 2013 at 12:06