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是也null不是。Neither 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.

适用于

另请参阅