浏览代码

EventRoute: remove additional check if event was handled

Dmitry Zhelnin 2 年之前
父节点
当前提交
a75753c942

+ 1 - 4
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 - 0
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;
+            }
         }
         }
     }
     }
 }
 }