【发布时间】:2014-08-28 11:25:59
【问题描述】:
在Windows 8.1 Pro 上使用.NET 4.5.1。在我的UserControl 我有网格。我需要在这个网格中预览和处理鼠标事件。所以我覆盖了PreviewMouseLeftButtonDown 事件:
myGrid.PreviewMouseLeftButtonDown +=
new MouseButtonEventHandler(myGrid_PreviewLeftButtonDown);
}
private void myGrid_PreviewLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// ...
e.Handled = true; // <-- IMPORTANT!
}
我的UserControl 也有一些InputBindings 正在静态构造函数中注册。例如:
CommandManager.RegisterClassInputBinding(typeof(MyUserControl),
new KeyBinding(MyCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
InputBinding 依赖于 PreviewMouseLeftButtonDown?!
现在,当我在我的PreviewMouseLeftButtonDown 处理程序中将e.Handled 设置为true 时,我的InputBindings 停止工作! 为什么?!我无法理解鼠标处理程序是如何链接到我的键盘快捷键的!
【问题讨论】:
标签: wpf inputbinding