C#如何禁用键绑定 [英] C# how to disable keybinding
问题描述
MenuItem 控件具有便捷的属性IsEnabled(继承自 UIElement ).这样,我可以在适当的情况下隐藏该菜单选项显示的命令.
The MenuItem control has the convenient property IsEnabled (inherited from UIElement). This allows me to, when appropriate, hide the command exposed by that menu option.
但是,如果该命令也绑定到某个键(例如Ctrl + K),则用户仍然可以访问它.如何将IsEnabled功能获取到 KeyBinding ?
But if that command is also bound to a key (e.g. Ctrl+K), the user can still access it. How do I get the IsEnabled functionality to a KeyBinding?
推荐答案
如果将KeyBinding
绑定到ICommand
,则只需设置 CanExecuteChanged
).
If you bind the KeyBinding
to an ICommand
, you can just set the ICommand.CanExecute
to false
(and potentially raise CanExecuteChanged
).
这将禁用" KeyBinding
,因为命令本身将被禁用.
This will "disable" the KeyBinding
since the command itself will be disabled.
这篇关于C#如何禁用键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!