0

In my application, I would like to allow user to drag item from a treeview to a canvas a generate a control for the dragged item. I have tried to use the PanelDragDropTarget to do that, but the canvas couldn't listen to the drop event.

In xaml file:

<toolkit:PanelDragDropTarget AllowDrop="True" Drop="drop_event">
    <Canvas Name="myCanvas" />
</toolkit:PanelDragDropTarget>

In xaml.cs file:

void drop_event(object sender, DropEventArgs e)
{
    MessageBox.Show("dropped");
}

What is the correct way to do that? Many thanks.

4

1 回答 1

0

Problem solved.

I created a class that inherit the DragDropTarget and wrap my canvas in it.

    public class CanvasDragDrop : DragDropTarget<Panel, UIElement>
    {
        //override methods if you needed
    }

In xaml file

    <CanvasDragDrop AllowDrop="True">
        <Canvas x:Name="myCanvas" />
    </CanvasDragDrop>
于 2013-05-10T06:06:10.947 回答