RoutedEventArgs.Source 屬性


取得或設定引發事件之物件的參考。Gets or sets a reference to the object that raised the event.

 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 將會繼續以原始呼叫所引發的第一個來源來報告來源 RaiseEventIf 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.