884 B
884 B
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:
{% tabs %} {% tab title="WPF" %}
static MyControl()
{
EventManager.RegisterClassHandler(typeof(MyControl), MyEvent, HandleMyEvent));
}
private static void HandleMyEvent(object sender, RoutedEventArgs e)
{
}
{% endtab %}
{% tab title="Avalonia" %}
static MyControl()
{
MyEvent.AddClassHandler<MyControl>(x => x.HandleMyEvent);
}
private void HandleMyEvent(object sender, RoutedEventArgs e)
{
}
{% endtab %} {% endtabs %}
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.