私はこれを持っていますMainWindow.xaml:
<Window.InputBindings>
<KeyBinding Key="O" Modifiers="Control" Command="{Binding OpenCommand}" />
<KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}" />
</Window.InputBindings>
独自のビューモデルを持つ子ビューがいくつかあります。たとえば、aFileViewとaFileViewModelとaDataViewとがありDataViewModelます。OpenCommand両方のビューモデルで、 :の実装があります。
public ICommand OpenCommand
{
get
{
if (openCommand == null)
{
openCommand = new RelayCommand(param => this.OpenFile());
}
return openCommand;
}
}
Ctrl+Oを押すOpenCommandと、アクティブなビューのビューモデルに対してコマンドが実行されます。したがって、のキーを押すと、FileViewがOpenFile()実行されます。にキーを入力するとDataView、OpenData()が実行されます。ある種のMDI振る舞い。
上記のコードは機能しません。
このタイプのキーバインド/コマンド処理をどのように実装しますか?