WPF ContextMenu uses (Shift-Right-Click)

I have a question with "ContextMenu" in WPF. Is there a way for the context menu to pop up only when executing "Shift-Right-Click"? I searched everywhere for this. ContextMenu, it seems, can only pop up when you click the "right click".

Does anyone have an idea?

+4
source share
1 answer

Try this ... your XAML context menu properties should look like this:

<ElementToWhichContextMenuIsAttached ContextMenu="{StaticResource MyContextMenu}" ContextMenuOpening="MyContextMenuOpening"/> 

And your code behind will look like this.

  /// <summary> /// This will suppress the context menu if the shift key is not pressed /// </summary> private void MyContextMenuOpening(object sender, ContextMenuEventArgs e) { // Show context menu as handled if no key is down. e.Handled = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)); } 
+6
source

Source: https://habr.com/ru/post/1344680/


All Articles