Why doesn't button click event “bubble up visual tree” to StackPanel as MSDN article states?

前端 未结 5 1612
鱼传尺愫
鱼传尺愫 2021-02-12 09:49

In the MSDN article Understanding Routed Events and Commands In WPF, it states

an event will bubble (propagate) up the visual tree from the source ele

5条回答
  •  余生分开走
    2021-02-12 10:21

    In addition, if you want the stackpanel to receive the event, change the stackpanel xaml to:

    
    

    and the event signature to:

    private void TheStackPanel_MouseDown(object sender, RoutedEventArgs e)
    

    In this case, the stackpanel will recieve the button's click event. However, clicking on the stackpanel itself won't fire any event, since it listens specifically to a button click.

提交回复
热议问题