Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF KeyGestures - Binding non alphanumeric keys

Should be a simple one, but I can't work out how to do it. Using WPF4 I want to Bind Ctrl + - to Zoom Out and Ctrl + = to Zoom In:

    <KeyBinding Command="{Binding Content.ZoomInCommand}" Gesture="Ctrl+="/>
    <KeyBinding Command="{Binding Content.ZoomOutCommand}" Gesture="Ctrl+-"/>

However, I'm getting errors: in the case of Ctrl + =:

Requested value '=' was not found.

Any ideas?

like image 404
Grokys Avatar asked Jul 29 '10 19:07

Grokys


1 Answers

Okay - it turns out that the = key does not exist (you can check this through the Key-enumeration - there is no entry for Equal or EqualSign)... I use an international keyboard, so you have to find which key sequence you hit to enter = (for me it's Shift + D0 on a danish keyboard) - and use that key-sequence.

So your XAML should be (in Denmark):

<KeyBinding Command="{Binding Content.ZoomInCommand}" Gesture="Ctrl+Shift+D0"/>

EDIT: I believe on an American system it is the OemPlus key - but you can check it by console-writeline'ing the e.Key argument in a key-down event handler)

EDIT2: the - key is OemMinus on my system.

like image 152
Goblin Avatar answered Sep 21 '22 06:09

Goblin