From 197429dbf936b791d0472f474c0eb9349eb6f0ed Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 26 Aug 2023 20:52:56 +0100 Subject: [PATCH] Fix theme not applying to notification area menu --- Bloxstrap/UI/Elements/Base/WpfUiWindow.cs | 24 +++++++++++++++++++ .../Elements/Bootstrapper/FluentDialog.xaml | 5 ++-- .../Bootstrapper/FluentDialog.xaml.cs | 10 +++----- .../Elements/ContextMenu/MenuContainer.xaml | 5 ++-- .../ContextMenu/MenuContainer.xaml.cs | 7 +++++- Bloxstrap/UI/Elements/Menu/MainWindow.xaml | 5 ++-- Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs | 13 +++------- .../UI/ViewModels/Menu/AppearanceViewModel.cs | 2 +- 8 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 Bloxstrap/UI/Elements/Base/WpfUiWindow.cs diff --git a/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs b/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs new file mode 100644 index 00000000..d941ea89 --- /dev/null +++ b/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Wpf.Ui.Appearance; +using Wpf.Ui.Controls; +using Wpf.Ui.Mvvm.Contracts; +using Wpf.Ui.Mvvm.Services; + +namespace Bloxstrap.UI.Elements.Base +{ + public class WpfUiWindow : UiWindow + { + private readonly IThemeService _themeService = new ThemeService(); + + public void ApplyTheme() + { + _themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light); + _themeService.SetSystemAccent(); + } + } +} diff --git a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml index 5602e8cd..40cc7f94 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml +++ b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml @@ -1,9 +1,10 @@ - - + diff --git a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs index 011a3025..7ab6cdc8 100644 --- a/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs @@ -15,8 +15,6 @@ namespace Bloxstrap.UI.Elements.Bootstrapper /// public partial class FluentDialog : IBootstrapperDialog { - private readonly IThemeService _themeService = new ThemeService(); - private readonly BootstrapperDialogViewModel _viewModel; public Bloxstrap.Bootstrapper? Bootstrapper { get; set; } @@ -69,15 +67,13 @@ public bool CancelEnabled public FluentDialog() { + InitializeComponent(); + ApplyTheme(); + _viewModel = new FluentDialogViewModel(this); DataContext = _viewModel; Title = App.Settings.Prop.BootstrapperTitle; Icon = App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource(); - - _themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light); - _themeService.SetSystemAccent(); - - InitializeComponent(); } private void UiWindow_Closing(object sender, CancelEventArgs e) diff --git a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml index d2ad0432..58d48b31 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml +++ b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml @@ -1,10 +1,11 @@ - - + diff --git a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs index 8354ced9..f2b8df07 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs +++ b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs @@ -2,6 +2,10 @@ using System.Windows.Controls; using System.Windows.Interop; +using Wpf.Ui.Appearance; +using Wpf.Ui.Mvvm.Contracts; +using Wpf.Ui.Mvvm.Services; + using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.UI.WindowsAndMessaging; @@ -26,7 +30,8 @@ public partial class MenuContainer public MenuContainer(ActivityWatcher? activityWatcher, DiscordRichPresence? richPresenceHandler) { InitializeComponent(); - + ApplyTheme(); + _activityWatcher = activityWatcher; _richPresenceHandler = richPresenceHandler; diff --git a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml index 6fee20ef..2a00fdde 100644 --- a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml +++ b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml @@ -1,4 +1,4 @@ - - + diff --git a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs index 968dabf7..2c748f91 100644 --- a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs @@ -14,21 +14,14 @@ namespace Bloxstrap.UI.Elements.Menu /// public partial class MainWindow : INavigationWindow { - private readonly IThemeService _themeService = new ThemeService(); - public MainWindow() { + InitializeComponent(); + ApplyTheme(); + App.Logger.WriteLine("MainWindow::MainWindow", "Initializing menu"); DataContext = new MainWindowViewModel(this); - SetTheme(); - InitializeComponent(); - } - - public void SetTheme() - { - _themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light); - _themeService.SetSystemAccent(); } public void OpenWiki(object? sender, EventArgs e) => Utilities.ShellExecute($"https://github.com/{App.ProjectRepository}/wiki"); diff --git a/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs index cb81afaa..9f8a453c 100644 --- a/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs @@ -63,7 +63,7 @@ public string Theme set { App.Settings.Prop.Theme = Themes[value]; - ((MainWindow)Window.GetWindow(_page)!).SetTheme(); + ((MainWindow)Window.GetWindow(_page)!).ApplyTheme(); } }