Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No entry for the Equals key in the System.Windows.Input.Key enum?

Tags:

.net

wpf

keyboard

I'm trying to set an InputGesture on a RoutedUICommand, hooking it up to catch when the user presses Ctrl + =. I'm using a KeyGesture object, but I can't see an entry in the System.Windows.Input.Key enum for the equals ('=') key.

What I was expecting was to be able to do the following:

ZoomIn = new RoutedUICommand("Zoom In", "ZoomIn", typeof(Window),
    new InputGestureCollection { 
        new KeyGesture(Key.Equals, ModifierKeys.Control) 
    });

Can anyone point me in the right direction, please?

like image 429
Mal Ross Avatar asked Mar 02 '11 17:03

Mal Ross


Video Answer


1 Answers

As pointed out by ChrisF, I needed to engage my brain a little. For what it's worth, the value generated when handling the KeyDown event is Key.OemPlus.

Update:
One consequence of this is that, if you're doing the same same as me and you're going to use the command in a menu, you'll probably want to use the overloaded constructor for KeyGesture that takes a 3rd parameter of displayString. For example:

new KeyGesture(Key.Equals, ModifierKeys.Control, "Ctrl+=")

Otherwise, you'll see the keyboard shortcut displayed as (in my case) "Ctrl+OemPlus", which isn't exactly desirable. Admittedly, the above still isn't great, but it's better than "OemPlus".

like image 70
Mal Ross Avatar answered Nov 11 '22 05:11

Mal Ross