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 techn开发者_JAVA技巧ique?
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/
精彩评论