From cc08405da9511bd554308eeeab8c7b63f598bbc3 Mon Sep 17 00:00:00 2001 From: Alexander Marek Date: Fri, 10 Jul 2026 12:46:30 +0200 Subject: [PATCH] @ (#21741) #21740 - SplitView must not steal BackRequested when its pane is closed When the SplitView is in Overlay or CompactOverlay mode it handled the TopLevel.BackRequested event even if its pane was not open, which broke system back navigation. Now it only closes the pane and marks the event handled when the pane is actually open; otherwise the event bubbles on. Adds unit tests covering both overlay modes. @ Co-authored-by: alexander.marek --- src/Avalonia.Controls/SplitView/SplitView.cs | 3 ++ .../SplitViewTests.cs | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Avalonia.Controls/SplitView/SplitView.cs b/src/Avalonia.Controls/SplitView/SplitView.cs index 14054d183f..ee44f2fbec 100644 --- a/src/Avalonia.Controls/SplitView/SplitView.cs +++ b/src/Avalonia.Controls/SplitView/SplitView.cs @@ -598,6 +598,9 @@ namespace Avalonia.Controls if (!IsInOverlayMode()) return; + if (!IsPaneOpen) + return; + SetCurrentValue(IsPaneOpenProperty, false); e.Handled = true; } diff --git a/tests/Avalonia.Controls.UnitTests/SplitViewTests.cs b/tests/Avalonia.Controls.UnitTests/SplitViewTests.cs index ad2dffc7bb..6beaf8c0f6 100644 --- a/tests/Avalonia.Controls.UnitTests/SplitViewTests.cs +++ b/tests/Avalonia.Controls.UnitTests/SplitViewTests.cs @@ -284,6 +284,43 @@ namespace Avalonia.Controls.UnitTests Assert.True(splitView.IsPaneOpen); } + [Theory] + [InlineData(SplitViewDisplayMode.Overlay)] + [InlineData(SplitViewDisplayMode.CompactOverlay)] + public void Top_Level_Back_Requested_Should_Not_Be_Handled_When_Pane_Is_Closed(SplitViewDisplayMode displayMode) + { + using var app = UnitTestApplication.Start(TestServices.StyledWindow + .With(globalClock: new MockGlobalClock())); + var wnd = new Window + { + Width = 1280, + Height = 720 + }; + var splitView = new SplitView + { + DisplayMode = displayMode + }; + wnd.Content = splitView; + wnd.Show(); + + // Pane is closed: the SplitView must ignore the event so back navigation can proceed. + Assert.False(splitView.IsPaneOpen); + + var closedArgs = new Interactivity.RoutedEventArgs(TopLevel.BackRequestedEvent); + wnd.RaiseEvent(closedArgs); + + Assert.False(closedArgs.Handled); + + // Pane is open: the SplitView should close it and handle the event. + splitView.IsPaneOpen = true; + + var openArgs = new Interactivity.RoutedEventArgs(TopLevel.BackRequestedEvent); + wnd.RaiseEvent(openArgs); + + Assert.True(openArgs.Handled); + Assert.False(splitView.IsPaneOpen); + } + [Fact] public void With_Default_IsPaneOpen_Value_Should_Have_Closed_Pseudo_Class_Set() {