Export (0) Print
Expand All

RoutedEventArgs Class

Contains state information and event data associated with a routed event.

System.Object
  System.EventArgs
    System.Windows.RoutedEventArgs
      More...

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

type RoutedEventArgs =  
    class 
        inherit EventArgs 
    end

The RoutedEventArgs type exposes the following members.

  NameDescription
Public methodRoutedEventArgs()Initializes a new instance of the RoutedEventArgs class.
Public methodRoutedEventArgs(RoutedEvent) Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier.
Public methodRoutedEventArgs(RoutedEvent, Object)Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier, and providing the opportunity to declare a different source for the event.
Top

  NameDescription
Public propertyHandledGets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.
Public propertyOriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.
Public propertyRoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance.
Public propertySourceGets or sets a reference to the object that raised the event.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodInvokeEventHandlerWhen overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnSetSourceWhen overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Different RoutedEventArgs can be used with a single RoutedEvent. This class is responsible for packaging the event data for a RoutedEvent, providing extra event state information, and is used by the event system for invoking the handler associated with the routed event.

For your custom event to support event routing, you need to register a RoutedEvent using the RegisterRoutedEvent method. This example demonstrates the basics of creating a custom routed event.

As shown in the following example, you first register a RoutedEvent using the RegisterRoutedEvent method. By convention, the RoutedEvent static field name should end with the suffix Event. In this example, the name of the event is Tap and the routing strategy of the event is Bubble. After the registration call, you can provide add-and-remove common language runtime (CLR) event accessors for the event.

Note that even though the event is raised through the OnTap virtual method in this particular example, how you raise your event or how your event responds to changes depends on your needs.

Note also that this example basically implements an entire subclass of Button; that subclass is built as a separate assembly and then instantiated as a custom class on a separate Extensible Application Markup Language (XAML) page. This is to illustrate the concept that subclassed controls can be inserted into trees composed of other controls, and that in this situation, custom events on these controls have the very same event routing capabilities as any native Windows Presentation Foundation (WPF) element does.

No code example is currently available or this language may not be supported.
<Window  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:custom="clr-namespace:SDKSample;assembly=SDKSampleLibrary"
    x:Class="SDKSample.RoutedEventCustomApp"

    >
    <Window.Resources>
      <Style TargetType="{x:Type custom:MyButtonSimple}">
        <Setter Property="Height" Value="20"/>
        <Setter Property="Width" Value="250"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Background" Value="#808080"/>
      </Style>
    </Window.Resources>
    <StackPanel Background="LightGray">
	    <custom:MyButtonSimple Name="mybtnsimple" Tap="TapHandler">Click to see Tap custom event work</custom:MyButtonSimple>
    </StackPanel>
</Window>

Tunneling events are created the same way, but with RoutingStrategy set to Tunnel in the registration call. By convention, tunneling events in WPF are prefixed with the word "Preview".

To see an example of how bubbling events work, see How to: Handle a Routed Event.

.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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

System.Object
  System.EventArgs
    System.Windows.RoutedEventArgs
      System.Activities.Presentation.Toolbox.ToolCreatedEventArgs
      System.Windows.Controls.ActivatingKeyTipEventArgs
      System.Windows.Controls.CalendarDateChangedEventArgs
      System.Windows.Controls.CalendarModeChangedEventArgs
      System.Windows.Controls.CleanUpVirtualizedItemEventArgs
      System.Windows.Controls.ContextMenuEventArgs
      System.Windows.Controls.InkCanvasGestureEventArgs
      System.Windows.Controls.InkCanvasStrokeCollectedEventArgs
      System.Windows.Controls.KeyTipAccessedEventArgs
      System.Windows.Controls.Primitives.DragCompletedEventArgs
      System.Windows.Controls.Primitives.DragDeltaEventArgs
      System.Windows.Controls.Primitives.DragStartedEventArgs
      System.Windows.Controls.Primitives.ScrollEventArgs
      System.Windows.Controls.Ribbon.RibbonDismissPopupEventArgs
      System.Windows.Controls.Ribbon.RibbonQuickAccessToolBarCloneEventArgs
      System.Windows.Controls.ScrollChangedEventArgs
      System.Windows.Controls.SelectionChangedEventArgs
      System.Windows.Controls.TextChangedEventArgs
      System.Windows.Controls.ToolTipEventArgs
      System.Windows.Controls.ValidationErrorEventArgs
      System.Windows.Data.DataTransferEventArgs
      System.Windows.DataObjectEventArgs
      System.Windows.DragEventArgs
      System.Windows.ExceptionRoutedEventArgs
      System.Windows.GiveFeedbackEventArgs
      System.Windows.Input.AccessKeyPressedEventArgs
      System.Windows.Input.CanExecuteRoutedEventArgs
      System.Windows.Input.ExecutedRoutedEventArgs
      System.Windows.Input.InputEventArgs
      System.Windows.MediaScriptCommandRoutedEventArgs
      System.Windows.Navigation.RequestNavigateEventArgs
      System.Windows.QueryContinueDragEventArgs
      System.Windows.RequestBringIntoViewEventArgs
      System.Windows.RoutedPropertyChangedEventArgs(T)
      System.Windows.SizeChangedEventArgs
      System.Windows.SourceChangedEventArgs
Show:
© 2014 Microsoft