Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

UIElement.RemoveHandler Method

Removes the specified routed event handler from this element.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

public void RemoveHandler(
	RoutedEvent routedEvent,
	Delegate handler
)

Parameters

routedEvent
Type: System.Windows.RoutedEvent

The identifier of the routed event for which the handler is attached.

handler
Type: System.Delegate

The specific handler implementation to remove from the event handler collection on this element.

Implements

IInputElement.RemoveHandler(RoutedEvent, Delegate)

The most common scenario for using this API is when you implement the 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 CLR 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. This behavior is consistent with CLR behavior of the -= operator.

Neither routedEvent nor handler may be null. Attempting to provide either value as null will raise an exception.

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.

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); }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft