From df44465669cbf4aa0fab6fa93d89eb5cfde3149e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Sep 2026 14:40:09 +0000 Subject: [PATCH 1/3] Initial plan From 1321ea95686102c37a198855cbbc40cb16f2b1a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Sep 2026 14:52:15 +0000 Subject: [PATCH 2/3] Fix Windows page restoration by preserving page-owned navigation content Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com> --- .../Elements/Window/WindowTests.Windows.cs | 81 +++++++++++++++++++ .../Platform/Windows/NavigationRootManager.cs | 15 +++- .../software/microsoft/sqmclient/values.xml | 4 + .../telemetry/default/v2/values.xml | 3 + .../persistentpropertybag/values.xml | 3 + .../visualstudio/telemetry/values.xml | 3 + 6 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml create mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml create mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml create mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml diff --git a/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs index 1d04aa5d5f78..c6d7e2fc64e9 100644 --- a/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs @@ -383,6 +383,87 @@ await CreateHandlerAndAddToWindow(window, async (handler) => }); } + [Fact] + public async Task RestoringSameShellPreservesContentAndTitleBar() + { + SetupBuilder(); + + var content = new Label { Text = "Issue 38619" }; + var shellPage = new ContentPage { Content = content }; + var shell = new Shell { CurrentItem = shellPage }; + var titleBar = new TitleBar { Title = "Retained Shell" }; + var window = new Window(shell) { TitleBar = titleBar }; + + await CreateHandlerAndAddToWindow(window, async handler => + { + await OnLoadedAsync(content); + var shellView = Assert.IsAssignableFrom(shell.Handler.PlatformView); + var shellContent = shellView.Content; + Assert.NotNull(shellContent); + + for (int i = 0; i < 2; i++) + { + var replacement = new ContentPage { Content = new Label { Text = "Replacement" } }; + window.Page = replacement; + await OnLoadedAsync(replacement); + await OnUnloadedAsync(content); + + window.Page = shell; + + // Disconnect must not clear the handler-owned ShellView's content. + Assert.Same(shellView, shell.Handler.PlatformView); + Assert.Same(shellContent, shellView.Content); + await OnLoadedAsync(shellPage); + await OnLoadedAsync(content); + + var rootView = GetWindowRootView(handler); + var platformContent = content.ToPlatform(handler.MauiContext); + Assert.Same(shellView, rootView.Content); + Assert.True(platformContent.IsLoaded); + Assert.Same(rootView.XamlRoot, platformContent.XamlRoot); + await AssertEventually(() => platformContent.ActualWidth > 0 && platformContent.ActualHeight > 0); + + Assert.Same(titleBar, rootView.TitleBar); + await OnLoadedAsync(titleBar); + Assert.True(titleBar.ToPlatform(handler.MauiContext).IsLoaded); + } + }); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task DisconnectOnlyClearsManagerCreatedNavigationView(bool useExistingNavigationView) + { + SetupBuilder(); + + await CreateHandlerAndAddToWindow(new ContentPage(), handler => + { + var manager = new NavigationRootManager(handler.PlatformView); + var content = new Microsoft.UI.Xaml.Controls.Border(); + var rootView = Assert.IsType(manager.RootView); + + try + { + manager.Connect(useExistingNavigationView ? new RootNavigationView { Content = content } : content); + var navigationView = Assert.IsType(rootView.Content); + Assert.Same(content, navigationView.Content); + + manager.Disconnect(); + + Assert.Null(rootView.Content); + if (useExistingNavigationView) + Assert.Same(content, navigationView.Content); + else + Assert.Null(navigationView.Content); + } + finally + { + manager.Disconnect(); + } + }); + } + // MinimizeAndThenMaximizingWorks test moved to UI tests (Issue14142) because // window activation events don't fire reliably on Helix VMs which run in // non-interactive Windows sessions. diff --git a/src/Core/src/Platform/Windows/NavigationRootManager.cs b/src/Core/src/Platform/Windows/NavigationRootManager.cs index 62a8aa53eecf..a974a65c147b 100644 --- a/src/Core/src/Platform/Windows/NavigationRootManager.cs +++ b/src/Core/src/Platform/Windows/NavigationRootManager.cs @@ -9,6 +9,7 @@ public partial class NavigationRootManager { readonly WeakReference _platformWindow; WindowRootView _rootView; + RootNavigationView? _navigationView; bool _disconnected = true; internal event EventHandler? OnApplyTemplateFinished; @@ -122,10 +123,14 @@ public virtual void Connect(UIElement? platformView) _rootView.Content = null; } - _rootView.Content = platformView is NavigationView ? platformView : new RootNavigationView() + if (_navigationView is not null) + _navigationView.Content = null; + + _navigationView = platformView is NavigationView ? null : new RootNavigationView() { Content = platformView }; + _rootView.Content = _navigationView ?? platformView; if (_disconnected && _platformWindow.TryGetTarget(out var platformWindow)) { @@ -149,8 +154,12 @@ public virtual void Disconnect() _rootView.AppWindowId = null; - if (_rootView.Content is RootNavigationView navView) - navView.Content = null; + // Only clear the wrapper we created, not a page-owned navigation view such as Shell. + if (_navigationView is not null) + { + _navigationView.Content = null; + _navigationView = null; + } _rootView.Content = null; _disconnected = true; diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml new file mode 100644 index 000000000000..e628946783e7 --- /dev/null +++ b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml @@ -0,0 +1,4 @@ + + {57A49F0B-FE0C-4784-ADBD-00C31045F89C} + {00000000-0000-0000-0000-000000000000} + \ No newline at end of file diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml new file mode 100644 index 000000000000..57fa6053bf35 --- /dev/null +++ b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml @@ -0,0 +1,3 @@ + + 0 + \ No newline at end of file diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml new file mode 100644 index 000000000000..7b56c76287a0 --- /dev/null +++ b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml @@ -0,0 +1,3 @@ + + 6533af06d3a45b98a595159d74ef8d0df39ac0006c80895c7bd34c60e42e12ba + \ No newline at end of file diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml new file mode 100644 index 000000000000..57fa6053bf35 --- /dev/null +++ b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml @@ -0,0 +1,3 @@ + + 0 + \ No newline at end of file From bbcf8e3f2d7f6207d55fbee3b5f19941f76c5fc0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Sep 2026 14:54:21 +0000 Subject: [PATCH 3/3] Remove generated Mono registry artifacts and ignore them Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com> --- .gitignore | 1 + .../CurrentUser/software/microsoft/sqmclient/values.xml | 4 ---- .../microsoft/visualstudio/telemetry/default/v2/values.xml | 3 --- .../visualstudio/telemetry/persistentpropertybag/values.xml | 3 --- .../software/microsoft/visualstudio/telemetry/values.xml | 3 --- 5 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml delete mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml delete mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml delete mode 100644 src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml diff --git a/.gitignore b/.gitignore index f747463d5017..894153192e78 100644 --- a/.gitignore +++ b/.gitignore @@ -381,6 +381,7 @@ snapshots-diff/ #install of dotnet version /.dotnet .dotnet +.mono/ temp .packages /src/Templates/.tempTemplateOutput diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml deleted file mode 100644 index e628946783e7..000000000000 --- a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/sqmclient/values.xml +++ /dev/null @@ -1,4 +0,0 @@ - - {57A49F0B-FE0C-4784-ADBD-00C31045F89C} - {00000000-0000-0000-0000-000000000000} - \ No newline at end of file diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml deleted file mode 100644 index 57fa6053bf35..000000000000 --- a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/default/v2/values.xml +++ /dev/null @@ -1,3 +0,0 @@ - - 0 - \ No newline at end of file diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml deleted file mode 100644 index 7b56c76287a0..000000000000 --- a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/persistentpropertybag/values.xml +++ /dev/null @@ -1,3 +0,0 @@ - - 6533af06d3a45b98a595159d74ef8d0df39ac0006c80895c7bd34c60e42e12ba - \ No newline at end of file diff --git a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml b/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml deleted file mode 100644 index 57fa6053bf35..000000000000 --- a/src/Graphics/src/Graphics/.mono/registry/CurrentUser/software/microsoft/visualstudio/telemetry/values.xml +++ /dev/null @@ -1,3 +0,0 @@ - - 0 - \ No newline at end of file