EventManager.RegisterRoutedEvent(String, RoutingStrategy, Type, Type) EventManager.RegisterRoutedEvent(String, RoutingStrategy, Type, Type) EventManager.RegisterRoutedEvent(String, RoutingStrategy, Type, Type) Method

定義

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 String 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 RoutingStrategy RoutingStrategy

作為列舉值的事件路由策略。The routing strategy of the event as a value of the enumeration.

handlerType
Type Type Type

事件處理常式的類型。The type of the event handler. 這必須是委派型別,而且不能是 nullThis must be a delegate type and cannot be null.

ownerType
Type Type 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. 路由事件識別項也會用於其他事件系統 APIAPIsThe routed event identifier is also used for other event system APIAPIs.

備註

使用這個方法的傳回值來建立唯一的靜態宣告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.

適用於