Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can WPF KeyBinding Key have several alternative values?

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 344
Queso Avatar asked Nov 09 '10 17: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 121
denis morozov Avatar answered Oct 24 '22 06:10

denis morozov


No, you can't do that.

like image 3
Rahul Soni Avatar answered Oct 24 '22 08:10

Rahul Soni