EventManager.RegisterRoutedEvent(String, RoutingStrategy, Type, Type) 方法

定义

Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 事件系统注册新的路由事件。Registers a new routed event with the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) event system.

public:
 static System::Windows::RoutedEvent ^ RegisterRoutedEvent(System::String ^ name, System::Windows::RoutingStrategy routingStrategy, Type ^ handlerType, Type ^ ownerType);
public static System.Windows.RoutedEvent RegisterRoutedEvent (string name, System.Windows.RoutingStrategy routingStrategy, Type handlerType, Type ownerType);
static member RegisterRoutedEvent : string * System.Windows.RoutingStrategy * Type * Type -> System.Windows.RoutedEvent

参数

name
String

路由事件的名称。The name of the routed event. 该名称在所有者类型中必须是唯一的,并且不能为 null 或空字符串。The name must be unique within the owner type and cannot be null or an empty string.

routingStrategy
RoutingStrategy

作为枚举值的事件的路由策略。The routing strategy of the event as a value of the enumeration.

handlerType
Type

事件处理程序的类型。The type of the event handler. 该类型必须为委托类型,并且不能为 nullThis must be a delegate type and cannot be null.

ownerType
Type

路由事件的所有者类类型。The owner class type of the routed event. 该类型不能为 nullThis cannot be null.

返回

新注册的路由事件的标识符。The identifier for the newly registered routed event. 现在可将该标识符对象存储为类中的静态字段,然后将其用作将处理程序附加到事件的方法的参数。This identifier object can now be stored as a static field in a class and then used as a parameter for methods that attach handlers to the event. 路由事件标识符也用于其他事件系统 API。The routed event identifier is also used for other event system APIs.

注解

使用此方法的返回值为唯一的 RoutedEvent 标识符字段创建静态声明。Use the return value of this method to create the static declaration for a unique RoutedEvent identifier field. 此字段应存储在所有者类型中。This field should be stored within the owner type.

有大量约定和最佳做法与如何在类中命名、注册和公开路由事件相关联。There are a considerable number of conventions and best practices associated with how routed events should be named, registered, and exposed in a class. 有关详细信息,请参阅路由事件概述For more information, see Routed Events Overview.

适用于