RoutedEventArgs.Source 属性

定义

获取或设置对引发事件的对象的引用。Gets or sets a reference to the object that raised the event.

public:
 property System::Object ^ Source { System::Object ^ get(); void set(System::Object ^ value); };
public object Source { get; set; }
member this.Source : obj with get, set
Public Property Source As Object

属性值

引发事件的对象。The object that raised the event.

注解

对于实际传递到引发它的元素之外的路由的任何冒泡路由事件,以及针对引发它的元素的任何隧道路由事件,Source 的值将不同于事件参数类的 sender 参数的值。For any bubbling routed event that has actually traveled the route beyond the element that raised it, and for any tunneling routed event that has not yet tunneled down to the element that raised it, the value of Source will be different than the value of the sender parameter of the event arguments class. 事件中涉及的两个元素中有哪些是最重要的(Source、引发它的元素或当前正在处理它的元素 sender)依赖于处理程序所寻址的应用程序逻辑。Which of the two elements involved in the event is of the most importance in any given handler (Source, the element that raised it, or sender, the element that is currently handling it) is dependent on the application logic that your handler is addressing.

通常仅当重写或实现其他调整事件源的 Api (例如,在处理事件的类时),才能设置此属性。Setting this property is typically only done when overriding or implementing other APIs that adjust event sources, such as when class handling an event. 不建议通过实例处理程序重置明显的事件源,特别是当处理程序未将事件标记为已处理时。Resetting apparent event sources from instance handlers is not recommended, particularly when the handler does not mark the event as handled.

如果重置 Source 以报告不同的事件源,OriginalSource 会继续将源报告为源 RaiseEvent 调用引发的第一个。If you do reset Source to report a different event source, OriginalSource will continue to report the source as first raised by the originating RaiseEvent call.

适用于

另请参阅