我想在 Prism4 桌面应用程序中为 DelegateCommand 启用 KeyBinding。例如,在我的 XAML 文件中,我有这个:
<Grid.InputBindings>
<KeyBinding Gesture="CTRL+A" Command="{Binding Command3}"/>
</Grid.InputBindings>
<StackPanel>
<Button Grid.Row="0" Grid.Column="1" Content="HitMe" prism:Click.Command="{Binding Command3}" />
</StackPanel>
在我的 ViewModel 我有这个:
public DelegateCommand<string> Command3 { get; private set; }
private void ExecuteCommand3(string commandParameter)
{
Debug.WriteLine("ExecuteCommand3");
}
private bool CanExecuteCommand3(string commandParameter)
{
return true;
}
当我按下 HitMe 按钮时,调试行输出,但按下 CTRL+A 无效。
我曾考虑使用 TestMvvmExample2341 中的 CommandReference 类,但这似乎重复了 Prism 4 机制的功能。
有没有一种简单的方法可以让 CTRL+A 调用 Prism4 中的 Command3?