Class Handlers
In WPF, class handlers for events can be added by calling EventManager.RegisterClassHandler. An example of registering a class handler in WPF might be:
WPF
Avalonia
1
static MyControl()
2
{
3
EventManager.RegisterClassHandler(typeof(MyControl), MyEvent, HandleMyEvent));
4
}
5
​
6
private static void HandleMyEvent(object sender, RoutedEventArgs e)
7
{
8
}
Copied!
1
static MyControl()
2
{
3
MyEvent.AddClassHandler<MyControl>(x => x.HandleMyEvent);
4
}
5
​
6
private void HandleMyEvent(object sender, RoutedEventArgs e)
7
{
8
}
Copied!
Notice that in WPF you have to add the class handler as a static method, whereas in Avalonia the class handler is not static: the notification is automatically directed to the correct instance.
Last modified 5mo ago
Export as PDF
Copy link