Handle right click command on RadContextMenu differently from left click

2 posts, 0 answers
  1. Russell
    Russell avatar
    9 posts
    Member since:
    Mar 2015

    Posted 11 Nov 2015 Link to this post

    Hi there,

    I have a RadContextMenu on a TreeListView and I've successfully hooked up the context menu to a command in my MVVM view model like this...

    ... 

              <telerik:RadContextMenu.ItemContainerStyle>
                <Style TargetType="telerik:RadMenuItem" BasedOn="{StaticResource RadMenuItemStyle}" d:DataContext="{d:DesignInstance data:IContextMenuItem}">
                  <Setter Property="Command" Value="{Binding Command}"/>

    This gets fired on both left clicks on the menu item as well as right clicks on the menu item.  Is it possible to handle right clicks separately?

    Thanks

    Russell

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 13 Nov 2015 Link to this post

    Hello Russel,

    You can register a ClassHandler to handle the right click like so:

    static MainWindow() 
        EventManager.RegisterClassHandler(typeof(RadMenuItem), Mouse.MouseDownEvent, new MouseButtonEventHandler(OnContextMenuOpening), false);
      
    public static void OnContextMenuOpening(object sender, MouseButtonEventArgs e) 
        if (e.RightButton == MouseButtonState.Pressed) 
        
            // your logic here
        
    }

    Please let me know if this works for you.

    Regards,
    Dilyan Traykov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top