|
|
@@ -2,7 +2,6 @@ using Avalonia;
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
using Avalonia.Markup.Xaml.Styling;
|
|
|
-using Avalonia.Threading;
|
|
|
using YZWater.Avalonia.Controls;
|
|
|
using YZWater.Avalonia.Views;
|
|
|
using YZWater.Core.Services;
|
|
|
@@ -18,13 +17,11 @@ public partial class App : Application
|
|
|
{
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
|
- // 棰勫姞杞戒袱涓富棰樿祫婧
|
|
|
_darkTheme = new ResourceInclude(new Uri("avares://YZWater.Avalonia/Themes/IndustrialTheme.axaml"))
|
|
|
{ Source = new Uri("avares://YZWater.Avalonia/Themes/IndustrialTheme.axaml") };
|
|
|
_lightTheme = new ResourceInclude(new Uri("avares://YZWater.Avalonia/Themes/IndustrialThemeLight.axaml"))
|
|
|
{ Source = new Uri("avares://YZWater.Avalonia/Themes/IndustrialThemeLight.axaml") };
|
|
|
|
|
|
- // 璁㈤槄涓婚鍒囨崲浜嬩欢
|
|
|
ThemeService.Instance.ThemeChanged += ApplyTheme;
|
|
|
}
|
|
|
|
|
|
@@ -32,8 +29,6 @@ public partial class App : Application
|
|
|
{
|
|
|
DatabaseService.Initialize();
|
|
|
PlcService.Initialize();
|
|
|
-
|
|
|
- // 鍒濆鍖栦富棰樹负娴呰壊
|
|
|
ThemeHelper.SetTheme(false);
|
|
|
|
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
@@ -44,17 +39,19 @@ public partial class App : Application
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 搴旂敤褰撳墠涓婚
|
|
|
- /// </summary>
|
|
|
private void ApplyTheme()
|
|
|
{
|
|
|
var resources = Resources.MergedDictionaries;
|
|
|
- if (resources.Count == 0 || _darkTheme == null || _lightTheme == null) return;
|
|
|
+ if (resources.Count == 0) return;
|
|
|
+
|
|
|
+ // 娓呯┖骞堕噸鏂板姞杞戒富棰樿祫婧
|
|
|
+ var targetTheme = ThemeService.Instance.IsDarkTheme ? _darkTheme : _lightTheme;
|
|
|
+ if (targetTheme == null) return;
|
|
|
|
|
|
- resources[0] = ThemeService.Instance.IsDarkTheme ? _darkTheme : _lightTheme;
|
|
|
+ resources.Clear();
|
|
|
+ resources.Add(targetTheme);
|
|
|
|
|
|
- // 鏇存柊鐢诲埛缂撳瓨骞堕氱煡鎺т欢閲嶇粯
|
|
|
+ // 鍚屾鏇存柊鐢诲埛缂撳瓨
|
|
|
ThemeHelper.SetTheme(ThemeService.Instance.IsDarkTheme);
|
|
|
}
|
|
|
}
|