Browse Source

Merge pull request #9918 from DmitryZhelnin/9559-receive-handled-events

Class Handlers: fix handlers with `handledEventsToo` parameter set ot `true`
pull/9998/head
Steven Kirk 4 years ago
committed by GitHub
parent
commit
7dd09cd2a5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Avalonia.Base/Interactivity/EventRoute.cs
  2. 26
      tests/Avalonia.Base.UnitTests/Interactivity/InteractiveTests.cs

5
src/Avalonia.Base/Interactivity/EventRoute.cs

@ -143,10 +143,7 @@ namespace Avalonia.Interactivity
// If we've got to a new control then call any RoutedEvent.Raised listeners. // If we've got to a new control then call any RoutedEvent.Raised listeners.
if (entry.Target != lastTarget) if (entry.Target != lastTarget)
{ {
if (!e.Handled) _event.InvokeRaised(entry.Target, e);
{
_event.InvokeRaised(entry.Target, e);
}
// If this is a direct event and we've already raised events then we're finished. // If this is a direct event and we've already raised events then we're finished.
if (e.Route == RoutingStrategies.Direct && lastTarget is object) if (e.Route == RoutingStrategies.Direct && lastTarget is object)

26
tests/Avalonia.Base.UnitTests/Interactivity/InteractiveTests.cs

@ -337,6 +337,27 @@ namespace Avalonia.Base.UnitTests.Interactivity
Assert.True(target.GetVisualParent<TestInteractive>().ClassHandlerInvoked); Assert.True(target.GetVisualParent<TestInteractive>().ClassHandlerInvoked);
} }
[Fact]
public void Typed_Class_Handlers_Should_Be_Called_For_Handled_Events()
{
var ev = new RoutedEvent<RoutedEventArgs>(
"test",
RoutingStrategies.Bubble | RoutingStrategies.Tunnel,
typeof(TestInteractive));
var target = CreateTree(ev, null, 0);
ev.AddClassHandler<TestInteractive>((x, e) => x.MarkEventAsHandled(e), RoutingStrategies.Bubble);
ev.AddClassHandler<TestInteractive>((x, e) => x.ClassHandler(e), RoutingStrategies.Bubble, handledEventsToo: true);
var args = new RoutedEventArgs(ev, target);
target.RaiseEvent(args);
Assert.True(args.Handled);
Assert.True(target.ClassHandlerInvoked);
Assert.True(target.GetVisualParent<TestInteractive>().ClassHandlerInvoked);
}
[Fact] [Fact]
public void GetObservable_Should_Listen_To_Event() public void GetObservable_Should_Listen_To_Event()
{ {
@ -443,6 +464,11 @@ namespace Avalonia.Base.UnitTests.Interactivity
{ {
ClassHandlerInvoked = true; ClassHandlerInvoked = true;
} }
public void MarkEventAsHandled(RoutedEventArgs e)
{
e.Handled = true;
}
} }
} }
} }

Loading…
Cancel
Save