Compartir a través de


UIElement.RemoveHandler Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Removes the specified routed event handler from this UIElement.

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

Syntax

'Declaration
Public Sub RemoveHandler ( _
    routedEvent As RoutedEvent, _
    handler As Delegate _
)
public void RemoveHandler(
    RoutedEvent routedEvent,
    Delegate handler
)

Parameters

  • handler
    Type: System.Delegate
    The specific handler implementation to remove from the event handler collection on this UIElement.

Exceptions

Exception Condition
ArgumentNullException

routedEvent or handler is nulla null reference (Nothing in Visual Basic).

ArgumentException

routedEvent does not represent a supported routed event.

-or-

handler does not implement a supported delegate.

NotImplementedException

Attempted to remove handler for an event not supported by the current platform variation.

Remarks

Important noteImportant Note:

RemoveHandler can only be used for the event handlers of the events that are supported by AddHandler. You cannot use RemoveHandler to remove handlers for general events that are added with the language-specific event wiring syntax (such as += in C#) or with event attribute in XAML. You should instead use language-specific event handler disconnection / removal syntax (such as -= in C#) for such event handlers.

Calling this method has no effect if there were no handlers registered with criteria that match 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 nulla null reference (Nothing in Visual Basic). Attempting to provide either value as nulla null reference (Nothing in Visual Basic) will raise an exception.

This method ignores the handledEventsToo parameter information of the symmetric AddHandler call.

Version Notes

Silverlight 3: Not all events noted in Remarks above are available in Silverlight 3. Silverlight 3 does not support right-click events, manipulation/touch events, drag/drop events, or IME support events. Attempting to add or remove handlers for these in Silverlight 3 throws an ArgumentException.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.