用于Ctrl + Shift + Zero的WPF KeyBinding手势不起作用

时间:2011-06-24 18:36:09

标签: wpf winapi windows-7 windows-vista key-bindings

我正在尝试使用WPF 3.5sp1映射 Ctrl + Shift + 0 ,但绑定不会触发。我正在使用的XAML是:

<KeyBinding Gesture="Ctrl+Shift+D0" Command="Blah"/>

我也尝试过:

<KeyBinding Key="D0" Modifiers="Ctrl+Shift" Command="Blah" />

还有许多其他组合,但都不起作用。手势=“Ctrl + D0”效果很好,或“Ctrl + Shift + OemPlus”等,所以我认为我的语法不是问题。我查看了Key enum并尝试查看“Shift-D0”是否重新映射到“OemParen”之类的东西,但没有任何东西向我跳出来。

我甚至在我的Window上放了一个PreviewKeyDown处理程序,我从未看到KeyEvent,其中Key == D0和Keyboard.ModifierKeys == Shift + Ctrl !事实上,当我按住 Ctrl + Shift 时,D0 keydown永远不会到达。

public MainWindow()
{
    InitializeComponent();
    this.PreviewKeyDown += MainWindow_PreviewKeyDown;
}

void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
    {
        Trace.WriteLine("shift is down!");
    }
    Trace.WriteLine(string.Format("key: {0}, system key: {1}, modifiers {2}", e.Key, e.SystemKey, e.KeyStates));
}

1 个答案:

答案 0 :(得分:5)

我发现了这个问题。罪魁祸首是Vista中的一项国际化变革(Win7继承)与键盘布局的变化有关。有KB topic讨论此问题并解决此问题:

Input method editor keyboard shortcut (CTRL+SHIFT+0) switches the input language in Vista