RoutedEvent Class
Represents and identifies a routed event and declares its characteristics.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The RoutedEvent type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | HandlerType | Gets the handler type of the routed event. |
![]() | Name | Gets the identifying name of the routed event. |
![]() | OwnerType | Gets the registered owner type of the routed event. |
![]() | RoutingStrategy | Gets the routing strategy of the routed event. |
| Name | Description | |
|---|---|---|
![]() | AddOwner | Associates another owner type with the routed event represented by a RoutedEvent instance, and enables routing of the event and its handling. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns the string representation of this RoutedEvent. (Overrides Object::ToString().) |
This class contains the Name, RoutingStrategy, HandlerType, and OwnerType properties. None of these members can have null values.
This class has a XAML usage that is exclusively intended for providing the value of the RoutedEvent property of an EventTrigger (or derived class), or for the Event property of an EventSetter (or derived class). For more information about EventTrigger, EventSetter, and the XAML usages for those classes, see Routed Events Overview.
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.
<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.
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.
