如何检测何时按下热键(快捷键)
如何检测何时在 WPF 中按下快捷键(例如 Ctrl + O)(独立于任何特定控件)?
我尝试捕获 KeyDown
但 KeyEventArgs
没有告诉我 Control 或 Alt 是否已关闭。
How do I detect when a shortcut key such as Ctrl + O is pressed in a WPF (independently of any particular control)?
I tried capturing KeyDown
but the KeyEventArgs
doesn't tell me whether or not Control or Alt is down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于弄清楚如何使用 XAML 中的命令来执行此操作。 不幸的是,如果您想使用自定义命令名称(不是像 ApplicationCommands.Open 这样的预定义命令之一),则有必要在代码隐藏中定义它,如下所示:
XAML 是这样的...
当然您需要处理程序:
I finally figured out how to do this with Commands in XAML. Unfortunately if you want to use a custom command name (not one of the predefined commands like ApplicationCommands.Open) it is necessary to define it in the codebehind, something like this:
The XAML goes something like this...
And of course you need a handler: