Browse Source

Add Interactive.AddHandler() for CancelRoutedEventArgs

This hopefully fixes unit tests due to wrong overload being selected by the compiler.
pull/9979/head
robloo 4 years ago
parent
commit
cfb90c8201
  1. 34
      src/Avalonia.Base/Interactivity/Interactive.cs

34
src/Avalonia.Base/Interactivity/Interactive.cs

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.VisualTree;
#nullable enable #nullable enable
@ -67,7 +66,38 @@ namespace Avalonia.Interactivity
typedHandler(sender, typedArgs); typedHandler(sender, typedArgs);
} }
var subscription = new EventSubscription(handler, routes, handledEventsToo, (baseHandler, sender, args) => InvokeAdapter(baseHandler, sender, args)); var subscription = new EventSubscription(handler, routes, handledEventsToo, InvokeAdapter);
AddEventSubscription(routedEvent, subscription);
}
/// <summary>
/// Adds a handler for the specified routed event.
/// </summary>
/// <param name="routedEvent">The routed event.</param>
/// <param name="handler">The handler.</param>
/// <param name="routes">The routing strategies to listen to.</param>
/// <param name="handledEventsToo">Whether handled events should also be listened for.</param>
public void AddHandler(
RoutedEvent<CancelRoutedEventArgs> routedEvent,
EventHandler<CancelRoutedEventArgs>? handler,
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
bool handledEventsToo = false)
{
routedEvent = routedEvent ?? throw new ArgumentNullException(nameof(routedEvent));
if (handler is null)
return;
static void InvokeAdapter(Delegate baseHandler, object sender, RoutedEventArgs args)
{
var typedHandler = (EventHandler<CancelRoutedEventArgs>)baseHandler;
var typedArgs = (CancelRoutedEventArgs)args;
typedHandler(sender, typedArgs);
}
var subscription = new EventSubscription(handler, routes, handledEventsToo, InvokeAdapter);
AddEventSubscription(routedEvent, subscription); AddEventSubscription(routedEvent, subscription);
} }

Loading…
Cancel
Save