PreviewMouseDoubleClic 已忽略处理
我有一个包含文本框的窗口。
在窗口和文本框中,我添加了一个 PreviewMouseDoubleClicHandler。
窗口中的处理程序:
private void PreviewMouseDoubleClickHandler(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("handler in the window");
e.Handled = true;
}
文本框中的处理程序:
private void PreviewMouseDoubleClickHandler(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("handler in the textBox");
e.Handled = true;
}
现在,当我双击文本框时,我希望首先进入窗口的处理程序,打印调试行,然后处理事件,然后仅此而已。我认为文本框的处理程序不会触发,因为该事件已经由窗口处理。
但这并不是这样工作的:我的两个处理程序都被解雇了。
奇怪的是:它与 PreviewMouseDown 事件配合得很好。如果我做完全相同的事情,但使用 PreviewMouseDownEvents,我会得到我期望的行为,即:窗口处理 mouseDown 并且不触发 textBox 的处理程序。
那么为什么这不适用于 doubleClick 事件呢?我做错了什么吗?它应该像这样工作吗? doubleClick 事件是否以不同的方式管理,导致我无法利用隧道的优势?
I have a window containing a textBox.
On both the window AND the textBox, I add a PreviewMouseDoubleClicHandler.
Handler in the window:
private void PreviewMouseDoubleClickHandler(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("handler in the window");
e.Handled = true;
}
handler in the textBox:
private void PreviewMouseDoubleClickHandler(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("handler in the textBox");
e.Handled = true;
}
now, when I double-click on the textBox, I expect to go first into the window's Handler, print the debug line, then handle the event, then nothing more. I thought the textBox's handler would not fire since the event has already been handled by the window.
This does not work like this though: I get both handlers fired.
The weird thing is: It works fine with the PreviewMouseDown event. If I do exactly the same thing but with PreviewMouseDownEvents, I get the behavior I expect, i.e.: the window handles the mouseDown and the textBox's handler is not fired.
so Why does this not work with the doubleClick event? Am I doing something wrong? Is it supposed to work like this? is the doubleClick Event managed in a different way that prevents me from using the advantages of tunneling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该行为是设计使然,请参阅:http: //msdn.microsoft.com/en-us/library/system.windows.controls.control.previewmousedoubleclick.aspx
The behavior is by design, please see: http://msdn.microsoft.com/en-us/library/system.windows.controls.control.previewmousedoubleclick.aspx