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

Handle right click command on RadContextMenu differently from left click

5 Answers 75 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Russell
Top achievements
Rank 1
Russell asked on 11 Nov 2015, 11:42 AM

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

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 13 Nov 2015, 04:52 PM
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
0
Steve
Top achievements
Rank 1
answered on 29 Nov 2018, 01:24 AM

I just came across this post trying to do something similar and it isn't quite working for me. I'm trying to prevent the right click from executing the command, but it still is even though I am setting e.Handled = True. Am I missing something?

 

        EventManager.RegisterClassHandler(GetType(Telerik.Windows.Controls.RadMenuItem), Mouse.MouseDownEvent, New MouseButtonEventHandler(AddressOf OnMenuItemMouseDown), False)
 
Sub OnMenuItemMouseDown(sender As Object, e As MouseButtonEventArgs)
    If e.RightButton = MouseButtonState.Pressed Then
        e.Handled = True
    End If
End Sub
0
Dilyan Traykov
Telerik team
answered on 03 Dec 2018, 10:46 AM
Hello Steve,

I've prepared a small sample project where the aforementioned approach works as expected.

Could you please have a look and let me know how this setup differs from the one you have at your end so that I can further assist you?

I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Steve
Top achievements
Rank 1
answered on 03 Dec 2018, 07:50 PM
It's really easy to modify your project. Go to "MessageBox.Show("Right click")" and take or comment the line out. Without the message popping up, the command is still executed. I just want nothing to happen if they right click on the menu.
0
Dilyan Traykov
Telerik team
answered on 04 Dec 2018, 05:06 PM
Hello Steve,

Please excuse me for overlooking this.

You should handle the MouseRightButtonUp event in this scenario in the following manner:

Public Sub New()
    InitializeComponent()
    EventManager.RegisterClassHandler(GetType(RadMenuItem), RadMenuItem.MouseRightButtonUpEvent, New MouseButtonEventHandler(AddressOf RightButtonUp), False)
End Sub
 
Public Sub RightButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    e.Handled = True
End Sub

Please let me know if this works for you.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeListView
Asked by
Russell
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Steve
Top achievements
Rank 1
Share this question
or