This documentation is archived and is not being maintained.

EventManager.RegisterRoutedEvent Method

Registers a new routed event with the Windows Presentation Foundation (WPF) event system, using the provided parameters.

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

public static RoutedEvent RegisterRoutedEvent (
	string name,
	RoutingStrategy routingStrategy,
	Type handlerType,
	Type ownerType
public static RoutedEvent RegisterRoutedEvent (
	String name, 
	RoutingStrategy routingStrategy, 
	Type handlerType, 
	Type ownerType
public static function RegisterRoutedEvent (
	name : String, 
	routingStrategy : RoutingStrategy, 
	handlerType : Type, 
	ownerType : Type
) : RoutedEvent
You cannot use methods in XAML.



The name of the routed event. The name must be unique within the owner type and cannot be a null reference (Nothing in Visual Basic) or an empty string.


The routing strategy of the event as a value of the enumeration.


The type of the event handler. This must be a delegate type and cannot be a null reference (Nothing in Visual Basic).


The owner class type of the routed event. This cannot be a null reference (Nothing in Visual Basic).

Return Value

The identifier for the newly registered routed event. This identifier object can now be stored as a static field in a class and then used as a parameter for methods that attach handlers to the event.

The caller of this method should be the static declaration for the unique RoutedEvent identifier field within the owner type.

There are a considerable number of conventions and best practices associated with how routed events should be named, registered, and exposed in a class. For more information, 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.

public class MyButtonSimple: Button
    // Create a custom routed event by first registering a RoutedEventID
    // This event uses the bubbling routing strategy
    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); }

    // This method raises the Tap event
       void RaiseTapEvent()
              RoutedEventArgs newEventArgs = new RoutedEventArgs(MyButtonSimple.TapEvent);
    // For demonstration purposes we raise the event when the MyButtonSimple is clicked
    protected override void OnClick()



      <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"/>
    <StackPanel Background="LightGray">
	    <custom:MyButtonSimple Name="mybtnsimple" Tap="TapHandler">Click to see Tap custom event work</custom:MyButtonSimple>

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 view the complete sample, including the implementation of the actual "Tap" event handler, see Custom Routed Events Sample. To see an example of how bubbling events work, see Handle a Routed Event.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0