This is a migrated thread and some comments may be shown as answers.

AddDragInitializeHandler DragInitializeEventArgs cancel issue

1 Answer 72 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ani
Top achievements
Rank 1
Ani asked on 22 Mar 2017, 01:28 PM

Hi,

I am having a problem with usage of cancel operation of DragInitializeEventArgs e in DragInitializeHandler.

After canceling particular items drag functionality it switches to parent item and marks it as chosen for dragging. 

  private void HandleDragInitialize(object sender, DragInitializeEventArgs e)
        {

if(some condition)

{e.cancel=true;}

}

the item that belongs to mentioned condition will not get dragged but his parent instead.

Any solution? 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 27 Mar 2017, 07:23 AM
Hello Ani,

This behavior is observed because when you cancel DragInitialize, the event bubbles to the parent item and start the drag operation for it. To prevent the drag from starting you can set the arguments Data and DragVisual. Here is an example in code:
private void OnDragInit(object sender, DragInitializeEventArgs e)
{
    if (drag is not allowed)
    {
        e.Data = null;
        e.DragVisual = null;
    }
}

I hope this helps.

Regards,
Martin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
TreeView
Asked by
Ani
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or