Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keybinding with more than one Key programmatically [duplicate]

Tags:

wpf

I have a KeyBinding with the Key set to D1 which is the 1 key. This isn't the same as NumPad1 key.

Is there a way to have something like:

Key="D1 && NumPad1"

So that pressing either D1 or NumPad1 would execute the command?

I've added a second KeyBinding one for each key D1 & NumPad1, but that seems like there should be a better way.

like image 835
Queso Avatar asked Nov 22 '22 11:11

Queso


2 Answers

Yes you can - comma delimited :-)

I am not certain if in the question you want to use two KeyBindings to signify that user would have to push the key twice. But that's what I was looking for. If that's the reason then this post will work.

For example, I wanted to use + to go forward, and ++ to double-go-forward, and - to go-back, -- to go double back in my app:

<KeyBinding Key="OemMinus"  Modifiers="Control" Command="{Binding GoBack}"/>
<KeyBinding Key="OemMinus,OemMinus" Modifiers="Control" Command="{Binding GoBack2X}"/>

The reason I figured it out, was that I know that in VisualStudio you have a ton of commands that have double key, like commenting, or collapsing regions. And you know that VS2010's written in WPF. So I looked on the VS menu, and there are ton of commands comma separated: View > Solution Navigator Cntr + W, F. I tried it and it worked!

like image 139
denis morozov Avatar answered Nov 24 '22 23:11

denis morozov


No, you can't do that.

like image 32
Rahul Soni Avatar answered Nov 25 '22 01:11

Rahul Soni