RoutedEventHandler 委托


表示将处理各种路由事件的方法,这些路由事件不包含除所有路由事件共有数据之外的其他特定事件数据。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. 这类路由事件很多;突出的示例包括 ClickLoadedThere are many such routed events; prominent examples include Click and Loaded.

写入路由事件的处理程序(而不是常规公共语言运行时)与常规公共语言运行时 (CLR) 事件的不同之处在于, sender 事件 (在其上附加和) 调用了处理程序的元素的事件是事件的源。The most noteworthy difference between writing a handler for a routed event as opposed to a general 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. 源在事件数据 () 中报告为属性 SourceThe 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. 在这种情况下, 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.

对于某些输入事件和 WPF 控件类的组合,引发事件的元素不是有机会处理该事件的第一个元素。For certain combinations of input events and WPF 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.