RoutedEventHandler RoutedEventHandler RoutedEventHandler RoutedEventHandler Delegate

定義

表示方法,這個方法會針對其特定事件資料不超過所有路由事件共通資料範圍的各種路由事件進行處理。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)

參數

sender
Object Object Object Object

附加事件處理常式的物件。The object where the event handler is attached.

繼承
RoutedEventHandlerRoutedEventHandlerRoutedEventHandlerRoutedEventHandler

備註

RoutedEventHandler委派會使用任何不會報告事件資料中的事件特定資訊的路由事件。The RoutedEventHandler delegate is used for any routed event that does not report event-specific information in the event data. 有許多這類路由的事件;重要的範例包括ClickLoadedThere 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). 之間的差異senderSource是路由事件的項目樹狀結構周遊期間路由傳送至不同的項目,事件的結果。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.

您可以使用senderSource物件參考,如果您故意不感興趣的直接或事件反昇路由事件路由的行為,而且您只想要處理路由事件,其第一次引發的項目上。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. 在此情況下,senderSource是相同的物件。In this circumstance, sender and Source are the same object.

如果您想要利用路由事件的固有功能,並據以撰寫處理常式,撰寫事件處理常式時,您將處理的事件資料的兩個最重要屬性是SourceHandledIf 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. 如果輸入的事件有預覽版本的事件,然後在元素樹狀結構的根目錄有第一個機會,可以設定Handledtrue中共用的事件資料,並可能會影響如何輸入的事件會回報給其事件路由中的其餘項目。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.

擴充方法

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.

適用於