|
@@ -6,11 +6,18 @@ namespace YZWater.Avalonia.Views;
|
|
|
|
|
|
|
|
public partial class ViewAView : UserControl
|
|
public partial class ViewAView : UserControl
|
|
|
{
|
|
{
|
|
|
|
|
+ private Border? _titleBar;
|
|
|
|
|
+ private Border? _statusBar;
|
|
|
|
|
+ private Border? _rootBorder;
|
|
|
|
|
+ private TextBlock? _titleText;
|
|
|
|
|
+ private TextBlock? _subtitleText;
|
|
|
|
|
+
|
|
|
public ViewAView()
|
|
public ViewAView()
|
|
|
{
|
|
{
|
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
|
AttachedToVisualTree += (_, _) =>
|
|
AttachedToVisualTree += (_, _) =>
|
|
|
{
|
|
{
|
|
|
|
|
+ FindElements();
|
|
|
ApplyTheme();
|
|
ApplyTheme();
|
|
|
ThemeHelper.ThemeChanged += ApplyTheme;
|
|
ThemeHelper.ThemeChanged += ApplyTheme;
|
|
|
};
|
|
};
|
|
@@ -20,20 +27,30 @@ public partial class ViewAView : UserControl
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void ApplyTheme()
|
|
|
|
|
|
|
+ private void FindElements()
|
|
|
{
|
|
{
|
|
|
- foreach (var visual in this.GetVisualDescendants())
|
|
|
|
|
|
|
+ foreach (var v 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;
|
|
|
|
|
|
|
+ if (v is Border b)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (b.Name == "TitleBar") _titleBar = b;
|
|
|
|
|
+ else if (b.Name == "StatusBar") _statusBar = b;
|
|
|
|
|
+ else if (b.Name == "RootBorder") _rootBorder = b;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (v is TextBlock tb)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (tb.Name == "TitleText") _titleText = tb;
|
|
|
|
|
+ else if (tb.Name == "SubtitleText") _subtitleText = tb;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void ApplyTheme()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_titleBar != null) _titleBar.Background = ThemeHelper.HeaderBg;
|
|
|
|
|
+ if (_statusBar != null) _statusBar.Background = ThemeHelper.NavBg;
|
|
|
|
|
+ if (_rootBorder != null) _rootBorder.Background = ThemeHelper.AppBg;
|
|
|
|
|
+ if (_titleText != null) _titleText.Foreground = ThemeHelper.HeaderText;
|
|
|
|
|
+ if (_subtitleText != null) _subtitleText.Foreground = ThemeHelper.HeaderSubtext;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|