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.
This commit is contained in:
2dust
2026-09-04 15:31:04 +08:00
parent 8ebbd7f4f8
commit 99328a14d2
2 changed files with 34 additions and 13 deletions
@@ -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<Control?> factory, Type vmType)
+32 -12
View File
@@ -405,6 +405,8 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
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<MainWindowViewModel>
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();