Export (0) Print
Expand All

EventManager.RegisterClassHandler Method (Type, RoutedEvent, Delegate)

Registers a class handler for a particular routed event.

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

public static void RegisterClassHandler (
	Type classType,
	RoutedEvent routedEvent,
	Delegate handler
)
public static void RegisterClassHandler (
	Type classType, 
	RoutedEvent routedEvent, 
	Delegate handler
)
public static function RegisterClassHandler (
	classType : Type, 
	routedEvent : RoutedEvent, 
	handler : Delegate
)
You cannot use methods in XAML.

Parameters

classType

The type of the class that is declaring class handling.

routedEvent

The routed event identifier of the event to handle.

handler

A reference to the class handler implementation.

Class handlers are invoked before instance handlers. You can implement a class handler that has the behavior of marking the event as handled. Therefore, instance handlers for a class-handled event are not invoked unless the instance handlers register specifically for handled events.

Many of the WPF base element events provide class handling virtual methods. By overriding these methods in classes that inherit the base classes, you can implement class handling without calling RegisterClassHandler in static constructors. These class handling methods typically exist for input events and have names that start with "On" and end with the name of the event being class handled. For more information, see Marking Routed Events as Handled, and Class Handling.

Using this signature, class handlers will be registered to invoke only in response to unhandled events. You can also register class handlers to invoke even if the event arguments are marked handled, by using the RegisterClassHandler(Type,RoutedEvent,Delegate,Boolean) signature, with handledEventsToo set to true.

The following example adds a handler for PreviewMouseLeftButtonDown, calling RegisterClassHandler.

static MyEditContainer()
{
  EventManager.RegisterClassHandler(typeof(MyEditContainer), PreviewMouseRightButtonDownEvent, new RoutedEventHandler(LocalOnMouseRightButtonDown));
}
internal static void LocalOnMouseRightButtonDown(object sender, RoutedEventArgs e)
{
  MessageBox.Show("this is invoked before the On* class handler on UIElement");
  //e.Handled = true; //uncommenting this would cause ONLY the subclass' class handler to respond
}

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

Community Additions

ADD
Show:
© 2014 Microsoft