tags:

views:

23

answers:

2

The way I created KeyBinding is something like

<KeyBinding Modifiers="Ctrl" Key="S" Command="{Binding SaveCommand}" />

but what if I needed 2 modifier keys? eg. Ctrl+Shift

+1  A: 
<KeyBinding Command="{Binding SaveCommand}"
            Gesture="Ctrl+Shift+S" />

Sometimes, MSDN documentation really helps ;-)
http://msdn.microsoft.com/fr-fr/library/system.windows.input.keybinding.aspx

Aurélien Ribon
+2  A: 

The documentation states that you can just separate the modifiers with the + character:

<KeyBinding Modifiers="Ctrl+Shift" Key="S" Command="{Binding SaveCommand}" />

See here for the gory details, relevant bit extracted below:


XAML

<object property="oneOrMoreModifierKeys"/>

XAML Values

oneOrMoreModifierKeys - One or more modifier keys, defined by the ModifierKeys enumeration, delimited with a "+" character.

You can also use a gesture on it's own rather than a key/modifier combo:

<KeyBinding Gesture="Ctrl+Shift+S" Command="{Binding SaveCommand}" />

as per that same documentation link:

When defining a KeyBinding in 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.

Both ways of setting the KeyGesture are equivalent and modify the same underlying object, but there will be a conflict if both are used. In the case when the Key, Modifiers, and the Gesture attributes are all set, the attribute which is defined last will be used for the KeyGesture.

paxdiablo