简体   繁体   English

WPF中的关键命令

[英]Key Commands in WPF

How can I set key commands like if the user presses Ctrl + Shift + N , a new dialog or action happens. 如何设置关键命令,如用户按下Ctrl + Shift + N ,则会出现新的对话框或操作。 And do I have to make a new event for each key command? 我是否必须为每个键命令创建一个新事件? How can I do this? 我怎样才能做到这一点?

You'll want to use the KeyBinding class . 您将要使用KeyBinding

KeyBinding allows you to bind a keyboard combination to any ICommand , including a RoutedCommand . KeyBinding允许您键盘组合绑定到任何ICommand ,包括RoutedCommand

You can use the command framework provided for WPF. 您可以使用为WPF提供的命令框架。 Some basic commands such as paste, copy, open, etc. are already defined by Microsoft... Microsoft已经定义了一些基本命令,如粘贴,复制,打开等...

You can, however, define new commands. 但是,您可以定义新命令。 A command can be executed when a button is clicked, a keyboard shortcut is pressed, a menu item is selected, etc. 单击按钮,按下键盘快捷键,选择菜单项等时,可以执行命令。

I am no WPF guru, but my understanding is that using commands is the way to go. 我不是WPF大师,但我的理解是使用命令是要走的路。

Take a loot at MSDN: http://msdn.microsoft.com/en-us/library/ms752308.aspx 在MSDN上获取战利品: http//msdn.microsoft.com/en-us/library/ms752308.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM