问题
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