检测哪个控件是重点?
我想为具有一个快捷键名称的两个按钮设置两个快捷键。
我如何检测 MVVM 中关注的是哪个控件?
I want to set two shortkeys for two buttons with one shortkey name.
How can i detect which control is focused in MVVM ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需将热键添加到其存在的任何逻辑范围即可。处理 WPF 热键的方法有很多,但是您的基本标记应如下所示:
这将运行
SaveACommand
if < code>UserControlA 具有键盘焦点,或者SaveBCommand
(如果UserControlB
具有键盘焦点)。You can simply add the hotkey to whatever scope is logical for it to exist in. There are many ways to handle hotkeys to WPF, however your basic markup should look something like this:
This will run
SaveACommand
ifUserControlA
has keyboard focus, orSaveBCommand
ifUserControlB
has keyboard focus.