Event Handler 代理人
表示方法，這個方法會針對其特定事件資料不超過所有路由事件共通資料範圍的各種路由事件進行處理。Represents the method that will handle various routed events that do not have specific event data beyond the data that is common for all routed events.
public delegate void RoutedEventHandler(System::Object ^ sender, RoutedEventArgs ^ e);
public delegate void RoutedEventHandler(object sender, RoutedEventArgs e);
type RoutedEventHandler = delegate of obj * RoutedEventArgs -> unit
Public Delegate Sub RoutedEventHandler(sender As Object, e As RoutedEventArgs)
附加事件處理常式的物件。The object where the event handler is attached.
事件資料。The event data.
RoutedEventHandler委派用於任何不會在事件資料中報告事件特定資訊的路由事件。The RoutedEventHandler delegate is used for any routed event that does not report event-specific information in the event data. 有許多這類路由事件;主要的範例Click包括Loaded和。There are many such routed events; prominent examples include Click and Loaded.
撰寫路由事件的處理常式與一般通用語言執行平台 (CLR)common language runtime (CLR)事件
sender相比, 最明顯的差異在於事件的 (附加和叫用處理程式的元素) 無法視為是來源事件的。The most noteworthy difference between writing a handler for a routed event as opposed to a general 通用語言執行平台 (CLR)common language runtime (CLR) event is that the
sender of the event (the element where the handler is attached and invoked) cannot be considered to necessarily be the source of the event. 來源會回報為事件資料 (Source) 中的屬性。The source is reported as a property in the event data (Source).
sender 和Source之間的差異, 是在透過專案樹狀結構進行路由事件的遍歷期間, 將事件路由傳送至不同元素的結果。A difference between
sender and Source is the result of the event being routed to different elements, during the traversal of the routed event through an element tree.
sender直接Source或反升路由事件的路由行為不感興趣, 而且只想要在第一次引發的專案上處理路由事件, 您可以將或用於物件參考。You can use either
sender or Source for an object reference if you are deliberately not interested in the routing behavior of a direct or bubbling routed event and you only intend to handle routed events on the elements where they are first raised. 在此情況下
sender , Source和是相同的物件。In this circumstance,
sender and Source are the same object.
如果您想要利用路由事件的固有功能, 並據以撰寫處理常式, 則在撰寫事件處理常式時, 您將會使用的兩個最重要的事件資料屬性Source為Handled和。If you do intend to take advantage of the inherent features of routed events and write your handlers accordingly, the two most important properties of the event data that you will work with when writing event handlers are Source and Handled.
對於輸入事件和WPFWPF控制項類別的某些組合, 引發事件的元素不是有機會處理它的第一個專案。For certain combinations of input events and WPFWPF control classes, the element that raises the event is not the first element that has the opportunity to handle it. 如果輸入事件具有事件的預覽版本, 則專案樹狀結構的根有第一個商機, 可以在共用的事件Handled資料
true中將設定為, 而且可能會影響輸入事件回報給其事件路由中其餘元素的方式。If the input event has a Preview version of the event, then the root of the element tree has first opportunity, can set Handled to
true in the shared event data, and can influence how the input event is reported to remaining elements in its event route. 預覽處理行為可以讓外觀不會如預期般引發特定路由事件。The Preview handling behavior can give the appearance that a particular routed event is not raised as expected. 如需詳細資訊, 請參閱預覽事件和輸入總覽。For more information, see Preview Events and Input Overview.
取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.