diff --git a/src/Avalonia.Base/Interactivity/IInteractive.cs b/src/Avalonia.Base/Interactivity/IInteractive.cs index cb1f559e73..add0389e42 100644 --- a/src/Avalonia.Base/Interactivity/IInteractive.cs +++ b/src/Avalonia.Base/Interactivity/IInteractive.cs @@ -48,5 +48,15 @@ namespace Avalonia.Interactivity var c = (Interactive)i; c.AddHandler(routedEvent, handler, routes, handledEventsToo); } + + public static void AddHandler(this IInteractive i, + RoutedEvent routedEvent, + EventHandler? handler, + RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, + bool handledEventsToo = false) + { + var c = (Interactive)i; + c.AddHandler(routedEvent, handler, routes, handledEventsToo); + } } } diff --git a/src/Avalonia.Base/Interactivity/Interactive.cs b/src/Avalonia.Base/Interactivity/Interactive.cs index 9bf1d276e0..926b6f34ae 100644 --- a/src/Avalonia.Base/Interactivity/Interactive.cs +++ b/src/Avalonia.Base/Interactivity/Interactive.cs @@ -18,7 +18,7 @@ namespace Avalonia.Interactivity /// Gets the interactive parent of the object for bubbling and tunneling events. /// IInteractive? IInteractive.InteractiveParent => ((IVisual)this).VisualParent as IInteractive; - + /// /// Adds a handler for the specified routed event. /// @@ -32,6 +32,25 @@ namespace Avalonia.Interactivity EventHandler? handler, RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, bool handledEventsToo = false) where TEventArgs : RoutedEventArgs + { + AddHandlerCore(routedEvent, handler, routes, handledEventsToo); + } + + public void AddHandler( + RoutedEvent routedEvent, + EventHandler? handler, + RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, + bool handledEventsToo = false) + { + AddHandlerCore(routedEvent, handler, routes, handledEventsToo); + } + + + private void AddHandlerCore( + RoutedEvent routedEvent, + EventHandler? handler, + RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, + bool handledEventsToo = false) where TEventArgs : RoutedEventArgs { routedEvent = routedEvent ?? throw new ArgumentNullException(nameof(routedEvent)); @@ -50,6 +69,7 @@ namespace Avalonia.Interactivity AddEventSubscription(routedEvent, subscription); } + /// /// Removes a handler for the specified routed event.