Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1540
Implement Drag and Drop in C# instead of XAML?
posted

Is there an example implementation of Drag & Drop at  runtime using C# code?  The only examples I've seen are in Xaml.

I need to Drag and Drop between a collection of XamTree's and a ListBox.  Also, need to move XamTreeItems around within a Tree.  These trees are created dynamically at runtime.

Parents
No Data
Reply
  • 6912
    Verified Answer
    posted

    Hi,

    Setting Drag & Drop at runtime using C# is pretty much the same as setting it from xaml. The only special thing that you should know is that DragDropManager.DropTarget and DragDropManager.DragSource are attached properties and setting them from C# can be done like this:

    item1.SetValue(DragDropManager.DragSourceProperty, ds); // ds is an object of type DragSource

    I've attached a sample that demonstrates this approach.

    Regards,

    Forum2.zip
Children