Joseph
Joseph

Reputation: 963

C# how to disable keybinding

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?

Upvotes: 2

Views: 4976

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564373

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.

Upvotes: 8

Related Questions