I currently use the onKeyDown event and an if/else statement to create keyboard shortcuts:
if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift && e.Key == Key.Tab) {
} else if (e.Key == Key.Tab) {
} ...
However, if I have quite a few more keyboard shortcuts, this gets messy.
Is there a better implementation?
You should look at implementing
<CommandBindings>and<InputBindings>:Your
<Button>then becomes:The
SettingsCanExecutemethod determines when the button is enabled and theSettingsExecutedmethod is called when the button is pressed or the key combination struck.You then don’t need the
KeyDownhandler.There’s a full tutorial on Switch On The Code.
More information on CommandBindings and InputBindings can be found on the MSDN.