Proch谩zet zdrojov茅 k贸dy

榛樿娴呰壊涓婚 + 鐢℅etVisualDescendants閬嶅巻瑙嗚鏍戞洿鏂颁富棰

纾 鏇 p艡ed 6 dny
rodi膷
revize
da86766a6e

+ 3 - 2
src/YZWater.Avalonia/App.axaml

@@ -1,7 +1,7 @@
 <Application xmlns="https://github.com/avaloniaui"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              x:Class="YZWater.Avalonia.App"
-             RequestedThemeVariant="Dark">
+             RequestedThemeVariant="Light">
 
     <Application.Styles>
         <FluentTheme />
@@ -11,7 +11,8 @@
     <Application.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
-                <ResourceInclude Source="Themes/IndustrialTheme.axaml"/>
+                <!-- 榛樿鍔犺浇娴呰壊涓婚 -->
+                <ResourceInclude Source="Themes/IndustrialThemeLight.axaml"/>
             </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
     </Application.Resources>

+ 3 - 0
src/YZWater.Avalonia/App.axaml.cs

@@ -33,6 +33,9 @@ public partial class App : Application
         DatabaseService.Initialize();
         PlcService.Initialize();
 
+        // 鍒濆鍖栦富棰樹负娴呰壊
+        ThemeHelper.SetTheme(false);
+
         if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
         {
             desktop.MainWindow = new MainWindow();

+ 19 - 13
src/YZWater.Avalonia/Views/ViewAView.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.VisualTree;
+using YZWater.Avalonia.Controls;
 
 namespace YZWater.Avalonia.Views;
 
@@ -7,21 +9,25 @@ public partial class ViewAView : UserControl
     public ViewAView()
     {
         InitializeComponent();
-        Loaded += (_, _) => ApplyCurrentTheme();
-        YZWater.Avalonia.Controls.ThemeHelper.ThemeChanged += ApplyCurrentTheme;
+        ThemeHelper.ThemeChanged += ApplyTheme;
+        ApplyTheme();
     }
 
-    private void ApplyCurrentTheme()
+    private void ApplyTheme()
     {
-        if (this.FindControl<Border>("TitleBar") is Border titleBar)
-            titleBar.Background = YZWater.Avalonia.Controls.ThemeHelper.HeaderBg;
-        if (this.FindControl<TextBlock>("TitleText") is TextBlock t)
-            t.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderText;
-        if (this.FindControl<TextBlock>("SubtitleText") is TextBlock s)
-            s.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderSubtext;
-        if (this.FindControl<Border>("StatusBar") is Border statusBar)
-            statusBar.Background = YZWater.Avalonia.Controls.ThemeHelper.NavBg;
-        if (this.FindControl<Border>("RootBorder") is Border root)
-            root.Background = YZWater.Avalonia.Controls.ThemeHelper.AppBg;
+        // 閬嶅巻瑙嗚鏍戞壘鍒板懡鍚嶅厓绱
+        foreach (var visual in this.GetVisualDescendants())
+        {
+            if (visual is Border border && border.Name == "TitleBar")
+                border.Background = ThemeHelper.HeaderBg;
+            else if (visual is Border sb && sb.Name == "StatusBar")
+                sb.Background = ThemeHelper.NavBg;
+            else if (visual is Border rb && rb.Name == "RootBorder")
+                rb.Background = ThemeHelper.AppBg;
+            else if (visual is TextBlock tb && tb.Name == "TitleText")
+                tb.Foreground = ThemeHelper.HeaderText;
+            else if (visual is TextBlock stb && stb.Name == "SubtitleText")
+                stb.Foreground = ThemeHelper.HeaderSubtext;
+        }
     }
 }

+ 18 - 13
src/YZWater.Avalonia/Views/ViewBView.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.VisualTree;
+using YZWater.Avalonia.Controls;
 
 namespace YZWater.Avalonia.Views;
 
@@ -7,21 +9,24 @@ public partial class ViewBView : UserControl
     public ViewBView()
     {
         InitializeComponent();
-        Loaded += (_, _) => ApplyCurrentTheme();
-        YZWater.Avalonia.Controls.ThemeHelper.ThemeChanged += ApplyCurrentTheme;
+        ThemeHelper.ThemeChanged += ApplyTheme;
+        ApplyTheme();
     }
 
-    private void ApplyCurrentTheme()
+    private void ApplyTheme()
     {
-        if (this.FindControl<Border>("TitleBar") is Border titleBar)
-            titleBar.Background = YZWater.Avalonia.Controls.ThemeHelper.HeaderBg;
-        if (this.FindControl<TextBlock>("TitleText") is TextBlock t)
-            t.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderText;
-        if (this.FindControl<TextBlock>("SubtitleText") is TextBlock s)
-            s.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderSubtext;
-        if (this.FindControl<Border>("StatusBar") is Border statusBar)
-            statusBar.Background = YZWater.Avalonia.Controls.ThemeHelper.NavBg;
-        if (this.FindControl<Border>("RootBorder") is Border root)
-            root.Background = YZWater.Avalonia.Controls.ThemeHelper.AppBg;
+        foreach (var visual in this.GetVisualDescendants())
+        {
+            if (visual is Border border && border.Name == "TitleBar")
+                border.Background = ThemeHelper.HeaderBg;
+            else if (visual is Border sb && sb.Name == "StatusBar")
+                sb.Background = ThemeHelper.NavBg;
+            else if (visual is Border rb && rb.Name == "RootBorder")
+                rb.Background = ThemeHelper.AppBg;
+            else if (visual is TextBlock tb && tb.Name == "TitleText")
+                tb.Foreground = ThemeHelper.HeaderText;
+            else if (visual is TextBlock stb && stb.Name == "SubtitleText")
+                stb.Foreground = ThemeHelper.HeaderSubtext;
+        }
     }
 }

+ 18 - 13
src/YZWater.Avalonia/Views/ViewCView.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.VisualTree;
+using YZWater.Avalonia.Controls;
 
 namespace YZWater.Avalonia.Views;
 
@@ -7,21 +9,24 @@ public partial class ViewCView : UserControl
     public ViewCView()
     {
         InitializeComponent();
-        Loaded += (_, _) => ApplyCurrentTheme();
-        YZWater.Avalonia.Controls.ThemeHelper.ThemeChanged += ApplyCurrentTheme;
+        ThemeHelper.ThemeChanged += ApplyTheme;
+        ApplyTheme();
     }
 
-    private void ApplyCurrentTheme()
+    private void ApplyTheme()
     {
-        if (this.FindControl<Border>("TitleBar") is Border titleBar)
-            titleBar.Background = YZWater.Avalonia.Controls.ThemeHelper.HeaderBg;
-        if (this.FindControl<TextBlock>("TitleText") is TextBlock t)
-            t.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderText;
-        if (this.FindControl<TextBlock>("SubtitleText") is TextBlock s)
-            s.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderSubtext;
-        if (this.FindControl<Border>("StatusBar") is Border statusBar)
-            statusBar.Background = YZWater.Avalonia.Controls.ThemeHelper.NavBg;
-        if (this.FindControl<Border>("RootBorder") is Border root)
-            root.Background = YZWater.Avalonia.Controls.ThemeHelper.AppBg;
+        foreach (var visual in this.GetVisualDescendants())
+        {
+            if (visual is Border border && border.Name == "TitleBar")
+                border.Background = ThemeHelper.HeaderBg;
+            else if (visual is Border sb && sb.Name == "StatusBar")
+                sb.Background = ThemeHelper.NavBg;
+            else if (visual is Border rb && rb.Name == "RootBorder")
+                rb.Background = ThemeHelper.AppBg;
+            else if (visual is TextBlock tb && tb.Name == "TitleText")
+                tb.Foreground = ThemeHelper.HeaderText;
+            else if (visual is TextBlock stb && stb.Name == "SubtitleText")
+                stb.Foreground = ThemeHelper.HeaderSubtext;
+        }
     }
 }

+ 18 - 13
src/YZWater.Avalonia/Views/ViewDView.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.VisualTree;
+using YZWater.Avalonia.Controls;
 
 namespace YZWater.Avalonia.Views;
 
@@ -7,21 +9,24 @@ public partial class ViewDView : UserControl
     public ViewDView()
     {
         InitializeComponent();
-        Loaded += (_, _) => ApplyCurrentTheme();
-        YZWater.Avalonia.Controls.ThemeHelper.ThemeChanged += ApplyCurrentTheme;
+        ThemeHelper.ThemeChanged += ApplyTheme;
+        ApplyTheme();
     }
 
-    private void ApplyCurrentTheme()
+    private void ApplyTheme()
     {
-        if (this.FindControl<Border>("TitleBar") is Border titleBar)
-            titleBar.Background = YZWater.Avalonia.Controls.ThemeHelper.HeaderBg;
-        if (this.FindControl<TextBlock>("TitleText") is TextBlock t)
-            t.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderText;
-        if (this.FindControl<TextBlock>("SubtitleText") is TextBlock s)
-            s.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderSubtext;
-        if (this.FindControl<Border>("StatusBar") is Border statusBar)
-            statusBar.Background = YZWater.Avalonia.Controls.ThemeHelper.NavBg;
-        if (this.FindControl<Border>("RootBorder") is Border root)
-            root.Background = YZWater.Avalonia.Controls.ThemeHelper.AppBg;
+        foreach (var visual in this.GetVisualDescendants())
+        {
+            if (visual is Border border && border.Name == "TitleBar")
+                border.Background = ThemeHelper.HeaderBg;
+            else if (visual is Border sb && sb.Name == "StatusBar")
+                sb.Background = ThemeHelper.NavBg;
+            else if (visual is Border rb && rb.Name == "RootBorder")
+                rb.Background = ThemeHelper.AppBg;
+            else if (visual is TextBlock tb && tb.Name == "TitleText")
+                tb.Foreground = ThemeHelper.HeaderText;
+            else if (visual is TextBlock stb && stb.Name == "SubtitleText")
+                stb.Foreground = ThemeHelper.HeaderSubtext;
+        }
     }
 }

+ 18 - 13
src/YZWater.Avalonia/Views/ViewEView.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.VisualTree;
+using YZWater.Avalonia.Controls;
 
 namespace YZWater.Avalonia.Views;
 
@@ -7,21 +9,24 @@ public partial class ViewEView : UserControl
     public ViewEView()
     {
         InitializeComponent();
-        Loaded += (_, _) => ApplyCurrentTheme();
-        YZWater.Avalonia.Controls.ThemeHelper.ThemeChanged += ApplyCurrentTheme;
+        ThemeHelper.ThemeChanged += ApplyTheme;
+        ApplyTheme();
     }
 
-    private void ApplyCurrentTheme()
+    private void ApplyTheme()
     {
-        if (this.FindControl<Border>("TitleBar") is Border titleBar)
-            titleBar.Background = YZWater.Avalonia.Controls.ThemeHelper.HeaderBg;
-        if (this.FindControl<TextBlock>("TitleText") is TextBlock t)
-            t.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderText;
-        if (this.FindControl<TextBlock>("SubtitleText") is TextBlock s)
-            s.Foreground = YZWater.Avalonia.Controls.ThemeHelper.HeaderSubtext;
-        if (this.FindControl<Border>("StatusBar") is Border statusBar)
-            statusBar.Background = YZWater.Avalonia.Controls.ThemeHelper.NavBg;
-        if (this.FindControl<Border>("RootBorder") is Border root)
-            root.Background = YZWater.Avalonia.Controls.ThemeHelper.AppBg;
+        foreach (var visual in this.GetVisualDescendants())
+        {
+            if (visual is Border border && border.Name == "TitleBar")
+                border.Background = ThemeHelper.HeaderBg;
+            else if (visual is Border sb && sb.Name == "StatusBar")
+                sb.Background = ThemeHelper.NavBg;
+            else if (visual is Border rb && rb.Name == "RootBorder")
+                rb.Background = ThemeHelper.AppBg;
+            else if (visual is TextBlock tb && tb.Name == "TitleText")
+                tb.Foreground = ThemeHelper.HeaderText;
+            else if (visual is TextBlock stb && stb.Name == "SubtitleText")
+                stb.Foreground = ThemeHelper.HeaderSubtext;
+        }
     }
 }

+ 1 - 1
src/YZWater.Core/Services/ThemeService.cs

@@ -11,7 +11,7 @@ public partial class ThemeService : ObservableObject
     public static ThemeService Instance => _instance ??= new ThemeService();
 
     [ObservableProperty]
-    private bool _isDarkTheme = true;
+    private bool _isDarkTheme = false;
 
     /// <summary>
     /// 涓婚鍙樻洿浜嬩欢锛堢敱 App.axaml.cs 璁㈤槄鎵ц瀹為檯鍒囨崲锛