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

Disable the Drag in Runtime in WPF

2 Answers 185 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Saw Lwin
Top achievements
Rank 1
Saw Lwin asked on 09 Apr 2014, 06:14 AM
Hi Telerik Support,

I am using telerik treeview (WPF) in my project. I am using DragDropManager to handle the drag drop events to perform the custom action. The issue I am facing right now is that I want to disable the treeviewitem from dragging based on the runtime value. I saw some thread asking the same question. However, the solution is using the old drag and drop method which is RadTreeView_PreviewDragStarted and some of them are Silverlight. I want to know the solution in WPF.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 11 Apr 2014, 01:35 PM
Hello,

You can disable the drag of a tree view item if you set the Cancel property of the event arguments to True ‚Äčin the DragInitialize handler.

public MainWindow()
{
    InitializeComponent();
    DragDropManager.AddDragInitializeHandler(this.treeView1, OnDragInitialize, true);
}
 
private void OnDragInitialize(object sender, DragInitializeEventArgs e)
{
    RadTreeView tree = (RadTreeView)sender;
    DataItem selectedItem = tree.SelectedItem as DataItem;
 
    if (!selectedItem.IsDraggable)
    {
        e.Cancel = true;
    }
}
You can also take a look at the following feedback item
 
I attached a sample project which demonstrates this approach. Please let me know if this works for you.

Regards,
Martin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Saw Lwin
Top achievements
Rank 1
answered on 14 Apr 2014, 01:23 AM
Hi Martin,

Thanks you so much for your reply. The solution you provided solved the issue I am facing.

With Best Regards,
Saw Lwin Oo
Tags
TreeView
Asked by
Saw Lwin
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Saw Lwin
Top achievements
Rank 1
Share this question
or