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)

参数

sender
Object

事件处理程序所附加到的对象。The object where the event handler is attached.

e
RoutedEventArgs

事件数据。The event data.

继承
RoutedEventHandler

注解

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). 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.

如果对直接或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.

如果您确实要利用路由事件的固有功能并相应地编写处理程序, 则在编写事件处理程序时将使用的事件数据的两个最重要的属性为Source和。 HandledIf 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)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于