UIElement.RemoveHandler(RoutedEvent, Delegate) UIElement.RemoveHandler(RoutedEvent, Delegate) UIElement.RemoveHandler(RoutedEvent, Delegate) Method

定義

從這個項目中移除指定的路由事件處理常式。Removes the specified routed event handler from this element.

public:
 virtual void RemoveHandler(System::Windows::RoutedEvent ^ routedEvent, Delegate ^ handler);
public void RemoveHandler (System.Windows.RoutedEvent routedEvent, Delegate handler);
abstract member RemoveHandler : System.Windows.RoutedEvent * Delegate -> unit
override this.RemoveHandler : System.Windows.RoutedEvent * Delegate -> unit

參數

routedEvent
RoutedEvent RoutedEvent RoutedEvent

要附加處理常式之路由事件的識別項。The identifier of the routed event for which the handler is attached.

handler
Delegate Delegate Delegate

要從這個項目上的事件處理常式集合中移除的特定處理常式實作。The specific handler implementation to remove from the event handler collection on this element.

實作

範例

下列範例會使用RemoveHandler事件包裝函式定義的一部分。The following example uses RemoveHandler as part of an event wrapper definition.

public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent(
    "Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButtonSimple));

// Provide CLR accessors for the event
public event RoutedEventHandler Tap
{
        add { AddHandler(TapEvent, value); } 
        remove { RemoveHandler(TapEvent, value); }
}
Public Shared ReadOnly TapEvent As RoutedEvent = EventManager.RegisterRoutedEvent("Tap", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(MyButtonSimple))

' Provide CLR accessors for the event
Public Custom Event Tap As RoutedEventHandler
    AddHandler(ByVal value As RoutedEventHandler)
        Me.AddHandler(TapEvent, value)
    End AddHandler

    RemoveHandler(ByVal value As RoutedEventHandler)
        Me.RemoveHandler(TapEvent, value)
    End RemoveHandler

    RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Me.RaiseEvent(e)
    End RaiseEvent
End Event

備註

最常見的案例,使用這APIAPI是您實作時會通用語言執行平台 (CLR)common language runtime (CLR)自訂路由事件,特別是當您實作在處理常式的 「 移除 」 邏輯時相關聯的 「 包裝函式 」 事件CLRCLR層級。The most common scenario for using this APIAPI is when you implement the 通用語言執行平台 (CLR)common language runtime (CLR) "wrapper" event that is associated with a custom routed event, specifically when you implement the "remove" logic for handlers at the CLRCLR level. 這個接下來的範例 < 備註 > 一節將說明此案例。The example that follows this remarks section illustrates this scenario.

如果沒有任何處理常式註冊以比對方法呼叫的輸入的參數的準則,則呼叫這個方法任何作用。Calling this method has no effect if there were no handlers registered with criteria that matches the input parameters for the method call.

如果多個處理常式已連結的事件處理常式存放區中,比對準則,也就是第一個處理常式。If more than one handler is attached that matched the criteria, only the first handler in the event handler store is removed. 此行為是配合CLRCLR行為-=運算子。This behavior is consistent with CLRCLR behavior of the -= operator.

既不routedEventhandler可能是nullNeither routedEvent nor handler may be null. 嘗試提供其中一個值做為null會引發例外狀況。Attempting to provide either value as null will raise an exception.

這個方法會忽略handledEventsToo加上第一個處理常式是否提供的參數資訊AddHandler(RoutedEvent, Delegate, Boolean)簽章,可讓已處理事件的處理。This method ignores the handledEventsToo parameter information, which is provided if the handler was first added with the AddHandler(RoutedEvent, Delegate, Boolean) signature that enables handling of already-handled events. 任一種類型的處理常式會移除。Either type of handler is removed.

適用於

另請參閱