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
Public Shared Function RegisterRoutedEvent (name As String, routingStrategy As RoutingStrategy, handlerType As Type, ownerType As Type) As 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.

傳回

RoutedEvent

新註冊路由事件的識別項。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.

備註

使用這個方法的傳回值,以建立唯一識別碼欄位的靜態宣告 RoutedEventUse 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.

適用於