語言

RoutedEvent.AddOwner(Type) 方法

定義

將另一個擁有者類型與由 RoutedEvent 實例代表的路由事件關聯,並允許事件的路由及其處理。

public:
 System::Windows::RoutedEvent ^ AddOwner(Type ^ ownerType);
public System.Windows.RoutedEvent AddOwner(Type ownerType);
member this.AddOwner : Type -> System.Windows.RoutedEvent
Public Function AddOwner (ownerType As Type) As RoutedEvent

參數

ownerType
Type

就是加入路由事件的類型。

傳回

事件的識別碼欄位。 此回傳值應用於設定一個公開的靜態唯讀欄位,以儲存所屬類型路由事件的識別碼。 此欄位通常以公開存取方式定義,因為使用者程式碼必須參考此欄位,才能在使用 AddHandler(RoutedEvent, Delegate, Boolean) 工具方法時附加任何路由事件的實例處理器。

範例

以下範例將當前類別加入為另一個事件的擁有者,該事件定義於不同類別中。 此處, AnotherEditContainer 是當前類別,而域 EditStateChangedEventRoutedEvent 定義為該類別的成員。 該 MyEditContainer 類別最初定義了事件,並以相同名稱 EditStateChangedEvent 的識別碼註冊。

public static readonly RoutedEvent EditStateChangedEvent  = MyEditContainer.EditStateChangedEvent.AddOwner(typeof(AnotherEditContainer));
Public Shared ReadOnly EditStateChangedEvent As RoutedEvent = MyEditContainer.EditStateChangedEvent.AddOwner(GetType(AnotherEditContainer))

備註

擁有者類型在內部用於以事件名稱解析事件。

適用於