4
votes

I am trying to do a to map Ctrl+Shift+0 with WPF 3.5sp1, but the binding does not fire. The XAML I'm using is:

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

I have also tried:

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

And many other combinations, none of which work. Gesture="Ctrl+D0" works great, or "Ctrl+Shift+OemPlus", etc. so I don't think my syntax is the issue. I have looked at the Key enum and tried to see if "Shift-D0" is remapped into something like "OemParen" but nothing is jumping out at me.

I've even put a PreviewKeyDown handler on my Window, and I never see a KeyEvent where Key == D0 and Keyboard.ModifierKeys == Shift + Ctrl! In fact, the D0 keydown never arrives at all when I am holding down Ctrl+Shift.

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
I have discovered that this is NOT a WPF issue, but the question itself is still valid and the answer does not seem to be well known. How should I update the quesiton summary to reflect this?Armentage

1 Answers

6
votes

I've discovered the problem. The culprit is an Internationalization change made in Vista (that Win7 inherits) related to how keyboard layouts are changed. There is a KB topic discussing this issue and work arounds:

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