Cancel Drag operation on right click

4 posts, 0 answers
  1. Balaram Barange
    Balaram Barange avatar
    28 posts
    Member since:
    Apr 2009

    Posted 09 Mar 2010 Link to this post

    Hi,
    I want to cancel drag operation on right click. i dragged item by pressing left click now i press right click(Simultaneously) and want to cancel drag operation.  This is same behavior as window expolere.

    Thanks
    Bala
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 09 Mar 2010 Link to this post

    Hello Balaram,

    You can attach a handler to the window and listen for handled right-click events:

    public Window1()
    {
        InitializeComponent();
                 
        this.AddHandler(FrameworkElement.MouseRightButtonDownEvent, new MouseButtonEventHandler(Window1_MouseRightButtonDown), true);
    }

    In the Window1_MouseRightButtonDown event handler you can simply cancel the drag:

    private void Window1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
        RadDragAndDropManager.CancelDrag();
    }

    Please find attached a sample project for further reference. Let me know if you have additional questions on the topic.

    Kind regards,
    Kiril Stanoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Balaram Barange
    Balaram Barange avatar
    28 posts
    Member since:
    Apr 2009

    Posted 04 Jun 2010 Link to this post

    Hi Telerik,
    Thanks for reply,
    I am able to canel drag when i capture right click event of Window.
    But I am developing a user control and that user control contain two rad tree which supports drag and drop. This user control is host in several other window.  so I want to capture right click event on user control not on parent window i.e main win. I am attaching you a snap that i captured from snoop utility. Image show the events that has fired when i drag a item and press right click.
    There is no event that i can capture from my user control so How can i capture event shown in Images.
     
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 08 Jun 2010 Link to this post

    Hi Balaram,

    For this particular scenario you will have to add the MouseRightButtonDownEvent handler to the window that is holding the UserControl (assuming the TreeViews are in this UserControl). In the constructor of the UserControl you can do the following:
     

    public TreeViewUserControl()
    {
        InitializeComponent();
        Dispatcher.BeginInvoke(new Action(() =>
        {
            var parentWindow = this.ParentOfType<Window>();
            if(parentWindow != null)
            {
                parentWindow.AddHandler(FrameworkElement.MouseRightButtonDownEvent, new MouseButtonEventHandler(TreeViewUserControl_MouseRightButtonDown), true);
            }
            else
            {
                MessageBox.Show("Error! Missing parent window!");
            }
        }), System.Windows.Threading.DispatcherPriority.ApplicationIdle);
    }

    For further information, please have a look at the attached project. Let me know if you have further questions or comments on the topic.


    Best wishes,
    Kiril Stanoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top