Browse Source

Non-generic overload for AddHandler

experiment/reflection-free
Nikita Tsukanov 4 years ago
parent
commit
26928c8cec
  1. 10
      src/Avalonia.Base/Interactivity/IInteractive.cs
  2. 22
      src/Avalonia.Base/Interactivity/Interactive.cs

10
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<RoutedEventArgs>? handler,
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
bool handledEventsToo = false)
{
var c = (Interactive)i;
c.AddHandler(routedEvent, handler, routes, handledEventsToo);
}
}
}

22
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.
/// </summary>
IInteractive? IInteractive.InteractiveParent => ((IVisual)this).VisualParent as IInteractive;
/// <summary>
/// Adds a handler for the specified routed event.
/// </summary>
@ -32,6 +32,25 @@ namespace Avalonia.Interactivity
EventHandler<TEventArgs>? handler,
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
bool handledEventsToo = false) where TEventArgs : RoutedEventArgs
{
AddHandlerCore(routedEvent, handler, routes, handledEventsToo);
}
public void AddHandler(
RoutedEvent routedEvent,
EventHandler<RoutedEventArgs>? handler,
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
bool handledEventsToo = false)
{
AddHandlerCore(routedEvent, handler, routes, handledEventsToo);
}
private void AddHandlerCore<TEventArgs>(
RoutedEvent routedEvent,
EventHandler<TEventArgs>? 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);
}
/// <summary>
/// Removes a handler for the specified routed event.

Loading…
Cancel
Save