C# how to disable keybinding

筅森魡賤 提交于 2019-12-20 03:57:11

问题


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.

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?


回答1:


If you bind the KeyBinding to an ICommand, you can just set the ICommand.CanExecute to false (and potentially raise CanExecuteChanged).

This will "disable" the KeyBinding since the command itself will be disabled.



来源:https://stackoverflow.com/questions/15706070/c-sharp-how-to-disable-keybinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!