|
@@ -1,4 +1,6 @@
|
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls;
|
|
|
|
|
+using Avalonia.VisualTree;
|
|
|
|
|
+using YZWater.Avalonia.Controls;
|
|
|
|
|
|
|
|
namespace YZWater.Avalonia.Views;
|
|
namespace YZWater.Avalonia.Views;
|
|
|
|
|
|
|
@@ -7,21 +9,25 @@ public partial class ViewAView : UserControl
|
|
|
public ViewAView()
|
|
public ViewAView()
|
|
|
{
|
|
{
|
|
|
InitializeComponent();
|
|
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;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|