EventManager 類別


提供事件相關公用程式方法,該方法可為類別擁有者註冊路由事件並加入類別處理常式。Provides event-related utility methods that register routed events for class owners and add class handlers.

public ref class EventManager abstract sealed
public static class EventManager
type EventManager = class
Public Class EventManager


下列範例示範如何使用這個類別,將新的路由事件註冊為類別成員,以及覆寫 CLRCLR 事件之 add 和 remove 的路由事件「包裝函式」技術。The following example show how to use this class to register a new routed event as a class member, along with the routed event "wrapper" technique of overriding the add and remove implementations for a CLRCLR event.

public static readonly RoutedEvent ButtonColorChangedEvent = EventManager.RegisterRoutedEvent("ButtonColorChanged",RoutingStrategy.Bubble,typeof(DependencyPropertyChangedEventHandler),typeof(Shirt));

public event RoutedEventHandler ButtonColorChanged  {
    add {AddHandler(ButtonColorChangedEvent,value);}
    remove { RemoveHandler(ButtonColorChangedEvent, value); }
Public Shared ReadOnly ButtonColorChangedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("ButtonColorChanged",RoutingStrategy.Bubble,GetType(DependencyPropertyChangedEventHandler),GetType(Shirt))

Public Custom Event ButtonColorChanged As RoutedEventHandler
    AddHandler(ByVal value As RoutedEventHandler)
    End AddHandler
    RemoveHandler(ByVal value As RoutedEventHandler)
        MyBase.RemoveHandler(ButtonColorChangedEvent, value)
    End RemoveHandler
    RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
    End RaiseEvent
End Event


這個類別最常用來註冊新的路由事件,並 RegisterRoutedEventThis class is most commonly used to register a new routed event, with RegisterRoutedEvent.

第二個最常見的 API 使用方式是 RegisterClassHandlerThe second most common API usage is RegisterClassHandler. 您可以使用這個方法,在類別上啟用路由事件的類別處理,或附加事件。You use this method to enable class handling of a routed event on the class, or an attached event. 如需詳細資訊,請參閱將路由事件標示為已處理以及類別處理For details, see Marking Routed Events as Handled, and Class Handling.



傳回已在事件系統中註冊的路由事件的識別項。Returns identifiers for routed events that have been registered to the event system.


針對已利用提供的擁有人型別註冊的事件,尋找所有路由事件識別項。Finds all routed event identifiers for events that are registered with the provided owner type.

RegisterClassHandler(Type, RoutedEvent, Delegate)

註冊特殊路由事件的類別處理常式。Registers a class handler for a particular routed event.

RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean)

使用處理事件資料已標示為已處理之事件的選項,註冊特定路由事件的類別處理常式。Registers a class handler for a particular routed event, with the option to handle events where event data is already marked handled.

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.