В небольшом проекте, над которым я сейчас работаю, у меня есть:
<Window.Resources>
<c:CommandReference x:Key="ExitCommandReference" Command="{Binding ExitCommand}" />
<c:CommandReference x:Key="ReloadCommandReference" Command="{Binding ReloadCommand}" />
</Window.Resources>
<Window.InputBindings>
<KeyBinding Key="F4" Modifiers="Alt" Command="{StaticResource ExitCommandReference}" />
<KeyBinding Key="F5" Command="{StaticResource ReloadCommandReference}"/>
</Window.InputBindings>
и в коде:
private DelegateCommand exitCommand;
private DelegateCommand reloadCommand;
public ICommand ExitCommand { get { return exitCommand ?? (exitCommand = new DelegateCommand(Exit)); } }
public ICommand ReloadCommand { get { return reloadCommand ?? (reloadCommand = new DelegateCommand(Reload)); } }
private static void Exit() { Application.Current.Shutdown(); }
private void Reload() { LoadData(); }