System.Windows.Input.Key:xaml中的方括号?

时间:2011-04-14 22:21:53

标签: wpf xaml key-bindings

使用XAML,我想声明一个带有Modifiers =“Control”和Key =“[”的KeyBinding。 '['字符不是System.Windows.Input.Key枚举的一部分。如何在XAML中声明此KeyBinding?

1 个答案:

答案 0 :(得分:3)

Key.OemOpenBrackets& Key.OemCloseBrackets

刚刚测试过它:

<Window.CommandBindings>
    <CommandBinding Command="Help" Executed="Help_Executed" CanExecute="Help_CanExecute"/>
</Window.CommandBindings>
<Window.InputBindings>
    <KeyBinding Key="OemOpenBrackets" Command="Help" Modifiers="Control"/>
</Window.InputBindings>
private void Help_Executed(object sender, ExecutedRoutedEventArgs e)
{
    MessageBox.Show("!");
}

private void Help_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
}

使用或不使用修饰符为我工作,可能您声明绑定的控件失焦。另一个原因可能是键盘布局,但我不确定如何解析键。