Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class-level event handler in WPF

Tags:

events

wpf

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?

like image 377
niao Avatar asked Feb 24 '23 18:02

niao


1 Answers

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/

like image 160
Pavlo Glazkov Avatar answered Mar 03 '23 07:03

Pavlo Glazkov