itc*_*chi 4 wpf xaml mvvm c#-4.0
我有一个WPF屏幕,有六个按钮.我想将每个与键绑定相关联.它们都是通过MVVM驱动的ICommand.
我目前有绑定事件而不是实际按钮的键绑定:
<UserControl.InputBindings>
<KeyBinding Key="N" Command="{Binding MyCommand}"/>
Run Code Online (Sandbox Code Playgroud)
但是,对于任何Keybinding工作,我必须设置至少1个按钮来关注代码隐藏.我真的不喜欢这样做,因为每个按钮/命令都有不同的规则,如果它是否活动,我有焦点动画,我更喜欢在页面加载时不活动.
这是可能的还是我必须设置焦点?
MaR*_*Ruf 13
您只需要将usercontrol的focusable设置为true,因为默认情况下某些元素不会将其设置为true
<UserControl Focusable="True">
Run Code Online (Sandbox Code Playgroud)
然后你必须在用户控件的加载事件中设置this.Focus()