私はこれを持っています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
振る舞い。
上記のコードは機能しません。
このタイプのキーバインド/コマンド処理をどのように実装しますか?