ColorValuesChanged now reapplies the theme

This commit is contained in:
Bugadinho 2025-01-06 20:54:32 -03:00
parent 4795bf8b66
commit e983814176
No known key found for this signature in database
GPG Key ID: B105A6D586EEBCFA

View File

@ -4,23 +4,27 @@ using Wpf.Ui.Appearance;
using Wpf.Ui.Controls; using Wpf.Ui.Controls;
using Wpf.Ui.Mvvm.Contracts; using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services; using Wpf.Ui.Mvvm.Services;
using Windows.UI.ViewManagement;
namespace Bloxstrap.UI.Elements.Base namespace Bloxstrap.UI.Elements.Base
{ {
public abstract class WpfUiWindow : UiWindow public abstract class WpfUiWindow : UiWindow
{ {
private readonly IThemeService _themeService = new ThemeService(); private readonly IThemeService _themeService = new ThemeService();
private UISettings _settings;
public WpfUiWindow() public WpfUiWindow()
{ {
ApplyTheme(); ApplyTheme();
_settings = new UISettings();
_settings.ColorValuesChanged += ColorValuesChanged;
} }
public void ApplyTheme() public void ApplyTheme()
{ {
_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light); _themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
_themeService.SetSystemAccent(); _themeService.SetSystemAccent();
#if QA_BUILD #if QA_BUILD
this.BorderBrush = System.Windows.Media.Brushes.Red; this.BorderBrush = System.Windows.Media.Brushes.Red;
this.BorderThickness = new Thickness(4); this.BorderThickness = new Thickness(4);
@ -37,5 +41,13 @@ namespace Bloxstrap.UI.Elements.Base
base.OnSourceInitialized(e); base.OnSourceInitialized(e);
} }
private async void ColorValuesChanged(UISettings sender, object args)
{
await Dispatcher.InvokeAsync(() =>
{
ApplyTheme();
});
}
} }
} }