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.

適用於