Wpf event not bubbling

前端 未结 4 1440
野趣味
野趣味 2021-01-03 06:50

Here is my XAML:



        
4条回答
  •  时光取名叫无心
    2021-01-03 07:05

    The MouseUp event is not fired on clicking the button.

    Because the first fires is an event at the Button.Click, and when it works, it conflicts with the event MouseUp. Quote from here:

    ButtonBase inherits from UIElement, a Button will also have access to all of the mouse button events defined for UIElement. Because the Button does something in response to button presses, it swallows the bubbling events (e.g. MouseLeftButtonDown and MouseDown). You can still detect these lower level button press events by adding handlers for the tunneling events (e.g. PreviewMouseLeftButtonDown and PreviewMouseDown).

    Try to replace the Button on Label, and you'll get the desired result:

    enter image description here

提交回复
热议问题