Disable the Drag in Runtime in WPF

3 posts, 1 answers
  1. Saw Lwin
    Saw Lwin avatar
    4 posts
    Member since:
    Apr 2014

    Posted 09 Apr 2014 Link to this post

    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. Answer
    Martin
    Admin
    Martin avatar
    1101 posts

    Posted 11 Apr 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Saw Lwin
    Saw Lwin avatar
    4 posts
    Member since:
    Apr 2014

    Posted 13 Apr 2014 Link to this post

    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
Back to Top