From 8a091cee0cdf138598b1d19a9ed5eae55dc9a186 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Sat, 16 Mar 2024 19:00:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20tabItems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Views/Windows/MainWindow.axaml.cs | 6 +++++- .../Services/Mvvm/UI/ViewModels/ViewModelManager.cs | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs b/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs index 69d09019bba..8cf9bb483ef 100644 --- a/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs +++ b/src/BD.WTTS.Client.Avalonia/UI/Views/Windows/MainWindow.axaml.cs @@ -44,10 +44,14 @@ internal bool SetStartDefaultPageName() if (NavigationService.Instance.CurrnetPage != null) return false; + var mw2 = IViewModelManager.Instance.MainWindow2; + if (mw2 == null) + return false; + Type? pageType = null; if (!string.IsNullOrEmpty(UISettings.StartDefaultPageName.Value)) { - var tabItems = IViewModelManager.Instance.MainWindow2?.TabItems; + var tabItems = mw2?.TabItems; if (tabItems == null) return false; diff --git a/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs b/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs index 0c9247aeea8..0d3522ffc61 100644 --- a/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs +++ b/src/BD.WTTS.Client/Services/Mvvm/UI/ViewModels/ViewModelManager.cs @@ -4,8 +4,8 @@ namespace BD.WTTS.Services.Implementation; internal sealed class ViewModelManager : ReactiveObject, IViewModelManager { bool disposedValue; - Dictionary viewModelDataCaches = new(); - Dictionary viewModelCaches = new(); + ConcurrentDictionary viewModelDataCaches = new(); + ConcurrentDictionary viewModelCaches = new(); /// /// 获取为当前主窗口提供的数据 @@ -69,7 +69,8 @@ public void Dispose(ViewModelBase viewModel) var vmType = viewModel.GetType(); var value = Serializable.SMP2(vmType, viewModel); viewModelDataCaches[vmType] = value; - viewModelCaches.Remove(vmType); + viewModelDataCaches[vmType] = value; + viewModelCaches.TryRemove(vmType, out var _); } void Dispose(bool disposing)