【发布时间】:2011-09-22 06:30:00
【问题描述】:
我正在尝试使用 WPF 3.5sp1 映射 Ctrl+Shift+0,但绑定不会触发。我使用的 XAML 是:
<KeyBinding Gesture="Ctrl+Shift+D0" Command="Blah"/>
我也试过了:
<KeyBinding Key="D0" Modifiers="Ctrl+Shift" Command="Blah" />
还有许多其他组合,但都不起作用。 Gesture="Ctrl+D0" 效果很好,或者“Ctrl+Shift+OemPlus”等,所以我认为我的语法不是问题。我查看了 Key 枚举并试图查看“Shift-D0”是否被重新映射为“OemParen”之类的东西,但没有任何东西跳出来。
我什至在我的窗口上放置了一个 PreviewKeyDown 处理程序,但我从来没有看到 KeyEvent 其中 Key == D0 和 Keyboard.ModifierKeys == Shift + Ctrl!事实上,当我按住 Ctrl+Shift 时,D0 按键根本不会出现。
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));
}
【问题讨论】:
-
我发现这不是 WPF 问题,但问题本身仍然有效,答案似乎并不为人所知。我应该如何更新问题摘要以反映这一点?
标签: wpf winapi windows-7 windows-vista key-bindings