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

添加路由事件的类型。

返回

RoutedEvent

事件的标识符字段。 应使用此返回值设置一个公共静态只读字段,该字段将把路由事件的表示形式标识符存储在所属类型上。 此字段通常通过公共访问定义,因为用户代码必须引用字段以在使用 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))

注解

按名称解析事件时,所有者类型在内部使用。

适用于