Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
System.Windows
 Handled Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
RoutedEventArgs..::.Handled Property

Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)
Visual Basic
Public Property Handled As Boolean
    Get
    Set
C#
public bool Handled { get; set; }
Visual C++
public:
property bool Handled {
    bool get ();
    void set (bool value);
}
F#
member Handled : bool with get, set

Property Value

Type: System..::.Boolean
If setting, set to true if the event is to be marked handled; otherwise false. If reading this value, true indicates that either a class handler, or some instance handler along the route, has already marked this event handled. false.indicates that no such handler has marked the event handled.
The default value is false.

Marking the event handled will limit the visibility of the routed event to listeners along the event route. The event does still travel the remainder of the route, but only handlers specifically added with HandledEventsToo true in the AddHandler(RoutedEvent, Delegate, Boolean) method call will be invoked in response. Default handlers on instance listeners (such as those expressed in Extensible Application Markup Language (XAML)) will not be invoked. Handling events that are marked handled is not a common scenario.

If you are a control author defining your own events, the decisions you make regarding event handling at the class level will impact users of your control as well as any users of derived controls, and potentially other elements that are either contained by your control or that contain your control. For more information, see Marking Routed Events as Handled, and Class Handling.

In very rare circumstances it is appropriate to handle events where Handled is marked true, and modify the event arguments by changing Handled to false. This can be necessary in certain areas of input events of controls, such as key handling of KeyDown versus TextInput where low level and high level input events compete for the handling, and each is attempting to work with a different routing strategy.

The following example implements an event handler that marks the event handled.

Visual Basic
    Protected Overrides Sub OnPreviewMouseRightButtonDown(ByVal e As System.Windows.Input.MouseButtonEventArgs)
        e.Handled = True 'suppress the click event and other leftmousebuttondown responders
        Dim ec As MyEditContainer = CType(e.Source, MyEditContainer)
        If ec.EditState Then
            ec.EditState = False
        Else
            ec.EditState = True
        End If
        MyBase.OnPreviewMouseRightButtonDown(e)
    End Sub
C#
protected override void OnPreviewMouseRightButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
    e.Handled = true; //suppress the click event and other leftmousebuttondown responders
    MyEditContainer ec = (MyEditContainer)e.Source;
    if (ec.EditState)
    { ec.EditState = false; }
    else
    { ec.EditState = true; }
    base.OnPreviewMouseRightButtonDown(e);
}

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker