开发者

Can WPF KeyBinding Key have several alternative values?

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 Nu开发者_StackOverflow中文版mPad1 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.


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!


No, you can't do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜