RoutedEvent.AddOwner(Type) 方法


将另一个所有者类型与 RoutedEvent 实例所表示的路由事件相关联,并允许事件的路由和其处理。Associates another owner type with the routed event represented by a RoutedEvent instance, and enables routing of the event and its handling.

 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



添加路由事件的类型。The type where the routed event is added.



事件的标识符字段。The identifier field for the event. 应使用此返回值设置一个公共静态只读字段,该字段将把路由事件的表示形式标识符存储在所属类型上。This return value should be used to set a public static read-only field that will store the identifier for the representation of the routed event on the owning type. 此字段通常通过公共访问定义,因为用户代码必须引用字段以在使用 AddHandler(RoutedEvent, Delegate, Boolean) 实用程序方法时,连接路由事件的任何实例处理程序。This field is typically defined with public access, because user code must reference the field in order to attach any instance handlers for the routed event when using the AddHandler(RoutedEvent, Delegate, Boolean) utility method.


下面的示例将当前类添加为其他类中定义的事件的另一个所有者。The following example adds the current class as another owner of an event defined in a different class. 此处, AnotherEditContainer 是当前类,并且 EditStateChangedEvent RoutedEvent 字段定义为该类的成员。Here, AnotherEditContainer is the current class, and the EditStateChangedEvent RoutedEvent field is defined as a member of that class. MyEditContainer该类最初定义了该事件,并为其注册了具有相同名称的 EditStateChangedEvent 标识符。The MyEditContainer class originally defined the event, registering it with the identically named EditStateChangedEvent identifier.

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


所有者类型在按名称解析事件时在内部使用。The owner type is used internally when resolving an event by name.