This documentation is archived and is not being maintained.

UIElement3D.AddHandler Method (RoutedEvent, Delegate, Boolean)

Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked for routed event that had already been marked as handled by another element along the event route.

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

public void AddHandler(
	RoutedEvent routedEvent,
	Delegate handler,
	bool handledEventsToo
You cannot use methods in XAML.


Type: System.Windows.RoutedEvent

An identifier for the routed event to be handled.

Type: System.Delegate

A reference to the handler implementation.

Type: System.Boolean

true to register the handler such that it is invoked even when the routed event is marked handled in its event data; false to register the handler with the default condition that it will not be invoked if the routed event is already marked handled.

The default is false.

Do not routinely ask to rehandle a routed event. For more information, see Remarks.

Processing low-level input events in a practical way is a complex task. Many controls implement behavior where a certain event is marked as handled, and is replaced by another more intuitive event. Generally, a control will only mark a platform input event as handled if there is some design intention for doing so. In certain scenarios, those design intentions might not be what your particular handling of the input event requires. It is for these scenarios that registering handlers with handledEventsToo as true is appropriate. But you should not do this routinely. Invoking handlers in response to all events even if handled will complicate your own application event processing logic. You may see a decrease in performance if the handler logic is substantial. You should reserve the use of attaching handlers for already-handled events for situations where you have already discovered during the development process that certain controls are handling events that you still want to handle with application logic.

Another technique for avoiding the class handling behavior of certain event-control combinations is to use that event's preview alternative. For example, if MouseLeftButtonDown is marked handled by class handling, you might be able to add handlers for PreviewMouseLeftButtonDown instead.

You can add the same handler for the same event multiple times without raising an exception. However, the handler is actually invoked multiple times when the event is handled. Therefore, consider how this behavior might have side effects that should be accounted for in your handler implementation.

You typically use this method to provide the implementation of the "add" accessor for the Microsoft .NET event access pattern of a custom routed event.

AddHandler is introduced in the .NET Framework version 3.5. For more information, see .NET Framework 3.5 Architecture.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1