Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a double-key shortcut? [duplicate]

Tags:

c#

wpf

shortcut

One can define a shortcut in WPF with

<KeyBinding Key="N" Modifiers="Control" Command="local:CustomCommands.MyCommand"/>

Shortcut CTRL + N is now defined.

Question: Is it also possible to define a double-key shortcut like Visual Studio 2012 uses it?

Example: CTRL + R, A is used to execute all unit tests.

like image 689
John Threepwood Avatar asked Nov 02 '22 06:11

John Threepwood


1 Answers

Use Gesture in conjunction with Key instead of modifier. As per MSDN:

When defining a KeyBinding in Extensible Application Markup Language (XAML) there are two ways to specify the KeyGesture. The first way to establish a KeyBinding in XAML is to define the Gesture attribute of the KeyBinding element, which enables a syntax to specify keys and modifiers as a single string, for example "CTRL+P". The second way is to define the Key attribute and the Modifiers attributes of the KeyBinding element.

<KeyBinding Gesture="Control+R" Key="A"
            Command="local:CustomCommands.MyCommand"/>

This will execute MyCommand in case Ctrl+R,A combination is used.

like image 59
Rohit Vats Avatar answered Nov 14 '22 07:11

Rohit Vats