RoutedEventArgs.Source vs Sender

前端 未结 4 1057
执念已碎
执念已碎 2020-12-05 11:44

What is the difference between sender and source in wpf event handling?

For example, say I had an ellipse in a canvas, and clicked on the ellipse:

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 12:40

    Hope this helps :)

    • RoutedEventArgs.OriginalSource - original object that first raised the event
    • RoutedEventArgs.Source - object that raised event. This is usually the same as OriginalSource but when dealing with Composite Controls it can be the parent that contains the OriginalSource object.*
    • Sender - Current element that is handling the event

    *Common cases where the source may be adjusted include content elements inside a content model for a control (the contents of a list item, for instance, will report the list item element as the Source and the actual element within the list item will be the OriginalSource).

    References:

    • http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.originalsource.aspx
    • http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.source.aspx (Includes mention of Sender)

提交回复
热议问题