Probably because the Button
is handling the event already, so it doesn't filter down to the Image control.
Why are you handling the MoustUp and MouseDown events on the Image
? Why not handle them on the Button
?
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
.
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.
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.
EDIT 3
Ok... I think I figured it out. I'm betting that the Button is "capturing" the Mouse on the MouseDown event. When this occurs, other controls will not receive MouseUp or MouseDown events (include the Preview versions) until the Mouse has been released.
See: http://books.google.com/books?id=nYl7J7z3KssC&pg=PA146#v=twopage&q&f=true
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…