wpf WPF将按钮绑定到按下的键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15944567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Bind button to key pressed
提问by Programmer Chick
I have not done WPF development before.
我之前没有做过WPF开发。
I am creating a calculator. I want the "one" button to be bound to the keyboard key "1". So the click function of my button must execute when the keyboard key "1" is pressed.
我正在创建一个计算器。我希望“一”按钮绑定到键盘键“1”。所以我的按钮的点击功能必须在按下键盘键“1”时执行。
Please advise on how to do this>
请告知如何执行此操作>
回答by Nahum
use this:
用这个:
http://msdn.microsoft.com/en-us/library/system.windows.input.keygesture.aspx
http://msdn.microsoft.com/en-us/library/system.windows.input.keygesture.aspx
<Window.InputBindings>
<KeyBinding Command="{Binding MyCommand}"
Gesture="CTRL+R" />
</Window.InputBindings>

