You should look at implementing <CommandBindings>
and <InputBindings>
:
<Window.CommandBindings>
<CommandBinding Command="Settings" CanExecute="SettingsCanExecute" Executed="SettingsExecuted" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Command="Settings" Key="S" Modifiers="Alt" />
</Window.InputBindings>
Your <Button>
then becomes:
<Button Height="50" Width="50" Margin="50,5,0,0" Command="Settings" />
The SettingsCanExecute
method determines when the button is enabled and the SettingsExecuted
method is called when the button is pressed or the key combination struck.
You then don't need the KeyDown
handler.
There's a full tutorial on Switch On The Code.
More information on CommandBindings and InputBindings can be found on the MSDN.