UIElement.RemoveHandler(RoutedEvent, Delegate) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Public Sub RemoveHandler (routedEvent As RoutedEvent, handler As Delegate)
Parameters
- routedEvent
- RoutedEvent
The identifier of the routed event for which the handler is attached.
- handler
- Delegate
The specific handler implementation to remove from the event handler collection on this element.
Implements
Examples
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
Remarks
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.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기