0

我想在 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?

4

1 回答 1

2

就是这样,也许您的问题与您认为的Focus有关,试试这个:

在运行时将焦点设置在 Button 上,然后应用击键。也看看这些帖子:

WPF MVVM KeyBinding 无法立即被识别并且并不总是有效

http://joyfulwpf.blogspot.com/2009/05/mvvm-commandreference-and-keybinding.html

于 2011-02-25T23:00:27.670 回答