键盘快捷键的命令路由
基本上我想创建一个在窗口范围内有效的键盘快捷键,而不仅仅是当焦点位于绑定它的控件内时启用。
更详细地说......
我有一个窗口它有 3 个控件:
- 工具栏
- 文本框
- 自定义控件
工具栏有一个绑定到命令 CustomCommands.CmdA
的按钮,并链接到键盘快捷键 Ctrl+T 。
我的自定义控件可以处理 CmdA
。当我运行应用程序并单击自定义控件时,CmdA
已启用并且工作正常。 Ctrl+T 也会导致命令触发。
但是,当我选择文本框时,我的自定义命令 CmdA
将被禁用。
我可以通过设置 CmdA
按钮的命令目标来纠正此问题。现在,当我选择文本框时,CmdA
仍然处于启用状态。
但键盘快捷键 Ctrl+T 没有任何作用。
有没有简单的方法可以更改键盘快捷键的范围?或者我是否需要在下方某个地方捕获按键,并找出它与哪个命令相关并自己路由它(如果是这样,是否有一个框架可以执行此操作?)
Basically I want to create a keyboard shortcut which is valid within the scope of a window, and not just enabled when focus is within the control that binds it.
in more detail....
I have a window which has 3 controls:
- a toolbar
- a textbox
- a Custom Control
The toolbar has a button bound to the Command CustomCommands.CmdA
, and linked to keyboard shortcut Ctrl+T.
My Custom Control can process CmdA
. When I run the app and click on my custom control CmdA
is enabled and works fine. Also Ctrl+T causes the command to fire.
However when I select the text box, my custom command CmdA
becomes disabled.
I can rectify this by setting the command target for CmdA
's button. Now when I select the textBox, CmdA
is still enabled.
But the Keyboard shortcut Ctrl+T does nothing.
Is there any easy way to change the scope of keyboard shortcuts? Or do I need to catch the keypress somewhere lower down, and work out which Command it relates to and route it myself (if so is there a framework within which to do this?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您通常只需要在窗口中指定输入绑定,例如:
对于内置应用程序命令(路由命令),您还需要窗口中的CommandBinding 。
For that you normally just need to specify the input bindings in the window, e.g.:
For built-in application commands (which are
RoutedCommands
) you needCommandBinding
in the window as well.