RoutedEventArgs vs EventArgs

前端 未结 3 1853
说谎
说谎 2020-12-30 02:15

I am learning WPF / Silverlight and saw in an MS vidcast that it is now recommended to use RoutedEventArgs over EventArgs; although it didn\'t say

3条回答
  •  自闭症患者
    2020-12-30 02:49

    Say we have a Button element containing other elements, a StackPanel, itself containing a TextBox and an Image element.

    The Button element should be able to handle a click event no matter if the Image that got clicked or if the TextBox was.

    Hence WPF provides a way to :

    • Propagate an event through element tree most of the time bubbling from the source element (here say the Image), to a higher level toward root element (for instance the button here).
    • Handle such a propagated event.

提交回复
热议问题