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?
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With