的MouseLeftButtonUp不火 [英] MouseLeftButtonUp does not fire

查看:180
本文介绍了的MouseLeftButtonUp不火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮

<Button>
    <Button.Template>
        <ControlTemplate>
            <StackPanel>
                <Image Source="share.png" 
                       MouseLeftButtonUp="Image_MouseLeftButtonUp"
                       MouseLeftButtonDown="Image_MouseLeftButtonDown" />
            </StackPanel>
        </ControlTemplate>
    </Button.Template>
</Button>

但问题是,不像的MouseLeftButtonDown的事件MouseLeftButtonUp不火。为什么?我该如何解决呢?谢谢你。

But the problem is that, unlike MouseLeftButtonDown, the event MouseLeftButtonUp does not fire. Why? How can I solve it? Thanks.

推荐答案

大概是因为按钮已经处理事件,因此它不下来过滤到图像控制。

Probably because the Button is handling the event already, so it doesn't filter down to the Image control.

你为什么要处理的图片的MoustUp和的MouseDown事件?为什么不处理他们在按钮

Why are you handling the MoustUp and MouseDown events on the Image? Why not handle them on the Button?

修改结果
快速浏览一下该事件的文件后,我看到路由策略<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseleftbuttonup%28v=vs.85%29.aspx\">MouseLeftButtonUp ,但实际的底层事件是<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.mouseup%28v=vs.85%29.aspx\">MouseUp其中有一个鼓泡的策略。所以,实际上,的MouseLeftButtonUp 应该有一个事实上的冒泡的策略,这意味着图片应该有机会处理在按钮事件之前

EDIT
After a quick look at the documentation for this event, I see that the routing strategy for MouseLeftButtonUp is Direct, but the actual underlying event is the MouseUp event which has a Bubbling strategy. So, in effect, MouseLeftButtonUp should have a de-facto bubbling strategy, meaning the Image should have the opportunity to handle the event before the Button.

听起来像别的可能会继续。如果图像设置为无影像控制,背景为空(不同于 Col​​or.Transparent ),那么WPF将视为不现有作为控制据鼠标事件去了。

Sounds like something else might be going on. If you set the Image to nothing on the Image control, and the background is null (different from Color.Transparent), then WPF will treat the control as not "existing" as far as mouse events go.

编辑2 结果
嗯......也许我最初的猜测是正确的毕竟。根据这一线索:结果
<一href=\"http://social.msdn.microsoft.com/forums/en/wpf/thread/e231919d-9fef-4aa5-9dcb-2c1eb68df25b/#306db880-ed50-45d2-819f-88d76f7148c1\">http://social.msdn.microsoft.com/forums/en/wpf/thread/e231919d-9fef-4aa5-9dcb-2c1eb68df25b/#306db880-ed50-45d2-819f-88d76f7148c1

按钮正在处理的MouseUp 事件。尝试使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.uielement.$p$pviewmouseup.aspx\">$p$pviewMouseUp然后检查,看哪个按钮被点击。

EDIT 2
Hmm... maybe my original guess was correct afterall. According to this thread:
http://social.msdn.microsoft.com/forums/en/wpf/thread/e231919d-9fef-4aa5-9dcb-2c1eb68df25b/#306db880-ed50-45d2-819f-88d76f7148c1
Button is handling the MouseUp event. Try using PreviewMouseUp and then checking to see which button was clicked.

编辑3 结果
好吧...我想我想通了。我敢打赌,该按钮位于MouseDown事件捕捉鼠标。发生这种情况时,其他控件将不会收到的MouseUp或MouseDown事件中,(包括preVIEW版本),直到老鼠已被释放。结果
参见:<一href=\"http://books.google.com/books?id=nYl7J7z3KssC&pg=PA146#v=twopage&q&f=true\">http://books.google.com/books?id=nYl7J7z3KssC&pg=PA146#v=twopage&q&f=true

这篇关于的MouseLeftButtonUp不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆