แก้ไข

แชร์ผ่าน


RoutedEvent.AddOwner(Type) Method

Definition

Associates another owner type with the routed event represented by a RoutedEvent instance, and enables routing of the event and its handling.

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

Parameters

ownerType
Type

The type where the routed event is added.

Returns

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. 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.

Examples

The following example adds the current class as another owner of an event defined in a different class. Here, AnotherEditContainer is the current class, and the EditStateChangedEvent RoutedEvent field is defined as a member of that class. 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))

Remarks

The owner type is used internally when resolving an event by name.

Applies to