HEllo, can someone explain me what class-level event handler is in WPF? I use routed events in WPF but currently I read a book and I found the author mentions about class-level event handler. What is the practical use of this technique?
Think of class handlers as static event handlers for a routed event. You might want to register such a handler if you want, for example, handle all mouse down events without any particular instance of the object involved. You would typically register it in a static constructor of a class:
static MyWindow()
{
EventManager.RegisterClassHandler(typeof(MyWindow), PreviewMouseLeftButtonDownEvent, new RoutedEventHandler(OnMouseLeftButtonDown));
}
See also:
http://msdn.microsoft.com/en-us/library/ms597875.aspx
http://karlshifflett.wordpress.com/2008/04/22/wpf-sample-series-eventmanagerregisterclasshandler/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With