Class Level Event Handler in WPF

Hello, can someone explain to me which class level event handler is in WPF? I use routed events in WPF, but I'm currently reading a book, and I found that the author mentions a class event handler. What is the practical use of this technique?

+4
source share
1 answer

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, to process all mouse events without any specific instance of the object. Usually you register it in the static constructor of the 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/

+8
source

Source: https://habr.com/ru/post/1344399/


All Articles