From 99328a14d22c268a805ecf33c7f6c49f102adce7 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 4 Sep 2026 15:31:04 +0800 Subject: [PATCH] Reset tab content when switching layouts Clear all auxiliary tab contents before applying a new grid orientation to prevent stale view reuse, and remove the delayed tab-index workaround. Also treat `ProfilesViewModel` as a transient view so its view is recreated like other dynamic tabs. --- .../Common/SimpleViewLocator.cs | 3 +- .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 44 ++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/v2rayN/v2rayN.Desktop/Common/SimpleViewLocator.cs b/v2rayN/v2rayN.Desktop/Common/SimpleViewLocator.cs index f589a245..e4b883ae 100644 --- a/v2rayN/v2rayN.Desktop/Common/SimpleViewLocator.cs +++ b/v2rayN/v2rayN.Desktop/Common/SimpleViewLocator.cs @@ -70,7 +70,8 @@ public class SimpleViewLocator : IDataTemplate { return vmType == typeof(MsgViewModel) || vmType == typeof(ClashProxiesViewModel) - || vmType == typeof(ClashConnectionsViewModel); + || vmType == typeof(ClashConnectionsViewModel) + || vmType == typeof(ProfilesViewModel); } private static Control CreateView(Func factory, Type vmType) diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 4a0260df..b06a599f 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -405,6 +405,8 @@ public partial class MainWindow : WindowBase var currentLayoutDisposables = new MultipleDisposable(); _layoutBindingsDisposable.Create(currentLayoutDisposables); + ClearLayoutContent(); + gridMain.IsVisible = orientation == EGirdOrientation.Horizontal; gridMain1.IsVisible = orientation == EGirdOrientation.Vertical; gridMain2.IsVisible = orientation == EGirdOrientation.Tab; @@ -445,22 +447,40 @@ public partial class MainWindow : WindowBase break; } - // workaround - Task.Run(async () => - { - await Task.Delay(5000); - Dispatcher.UIThread.Post(() => - { - ViewModel?.TabMainSelectedIndex = 0; - tabMain.SelectedIndex = 0; - tabMain1.SelectedIndex = 0; - tabMain2.SelectedIndex = 0; - }); - }); + //// workaround + //Task.Run(async () => + //{ + // await Task.Delay(5000); + // Dispatcher.UIThread.Post(() => + // { + // ViewModel?.TabMainSelectedIndex = 0; + // tabMain.SelectedIndex = 0; + // tabMain1.SelectedIndex = 0; + // tabMain2.SelectedIndex = 0; + // }); + //}); RestoreUI(); } + private void ClearLayoutContent() + { + tabProfiles.Content = null; + tabMsgView.Content = null; + tabClashProxies.Content = null; + tabClashConnections.Content = null; + + tabProfiles1.Content = null; + tabMsgView1.Content = null; + tabClashProxies1.Content = null; + tabClashConnections1.Content = null; + + tabProfiles2.Content = null; + tabMsgView2.Content = null; + tabClashProxies2.Content = null; + tabClashConnections2.Content = null; + } + private void AddHelpMenuItem() { var coreInfo = CoreInfoManager.Instance.GetCoreInfo();