From e64b1dd485542ac52555e6d67ced483d3e9acdaf Mon Sep 17 00:00:00 2001 From: Krzysztof Lorenc Date: Tue, 9 Apr 2019 17:45:57 +0200 Subject: [PATCH] Workaround for a problem with apply of dark theme. For now, the dark mode (enable or disable) is applied also when config dialog is opened because there is some problem with correct apply of the theme in About page - might be some issue with the Material Design in XAML library. --- .../Config/MainConfigPage.xaml.cs | 18 ++------ .../Config/View/ConfigWindow.xaml.cs | 46 ++++++++++++++++++- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/Soloplan.WhatsON.GUI/Config/MainConfigPage.xaml.cs b/src/Soloplan.WhatsON.GUI/Config/MainConfigPage.xaml.cs index 4ee0fb6..1fe51a2 100644 --- a/src/Soloplan.WhatsON.GUI/Config/MainConfigPage.xaml.cs +++ b/src/Soloplan.WhatsON.GUI/Config/MainConfigPage.xaml.cs @@ -19,10 +19,11 @@ public partial class MainConfigPage : Page /// /// The Theme helper. /// - private ThemeHelper themeHelper; + private readonly ThemeHelper themeHelper; - public MainConfigPage(ConfigViewModel configurationViewModel) + public MainConfigPage(ConfigViewModel configurationViewModel, ThemeHelper themeHelper) { + this.themeHelper = themeHelper; this.DataContext = configurationViewModel; this.InitializeComponent(); } @@ -54,18 +55,7 @@ private void LightOrDarkModeToggleButtonUnchecked(object sender, RoutedEventArgs private void SwitchLightDarkMode(ToggleButton lightDarkToggleButton) { var isDark = lightDarkToggleButton.IsChecked ?? false; - - var currentThemeHelper = this.GetThemeHelper(); - currentThemeHelper.ApplyLightDarkMode(isDark); - } - - /// - /// Gets the theme helper. - /// - /// The Theme helper. - private ThemeHelper GetThemeHelper() - { - return this.themeHelper ?? (this.themeHelper = new ThemeHelper()); + this.themeHelper.ApplyLightDarkMode(isDark); } } } diff --git a/src/Soloplan.WhatsON.GUI/Config/View/ConfigWindow.xaml.cs b/src/Soloplan.WhatsON.GUI/Config/View/ConfigWindow.xaml.cs index 9351caa..0c59dde 100644 --- a/src/Soloplan.WhatsON.GUI/Config/View/ConfigWindow.xaml.cs +++ b/src/Soloplan.WhatsON.GUI/Config/View/ConfigWindow.xaml.cs @@ -58,6 +58,16 @@ public partial class ConfigWindow : Window /// private AboutPage aboutPage; + /// + /// The Theme helper. + /// + private ThemeHelper themeHelper; + + /// + /// The window shown flag. + /// + private bool windowShown; + /// /// Initializes a new instance of the class. /// @@ -84,6 +94,24 @@ public ConfigWindow(ApplicationConfiguration configuration) /// public event EventHandler ConfigurationApplying; + /// + /// Raises the event. + /// + /// The instance containing the event data. + protected override void OnContentRendered(EventArgs e) + { + base.OnContentRendered(e); + + if (this.windowShown) + { + return; + } + + this.windowShown = true; + + this.GetThemeHelper().ApplyLightDarkMode(this.configurationSource.DarkThemeEnabled); + } + /// /// Handles the SelectionChanged event of the ListBox control. /// @@ -115,7 +143,7 @@ private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) switch (selectedItemTag) { case MainListItemTag: - this.mainPage = this.mainPage ?? new MainConfigPage(this.configurationViewModel); + this.mainPage = this.mainPage ?? new MainConfigPage(this.configurationViewModel, this.GetThemeHelper()); this.ConfigFrame.Content = this.mainPage; return; case SubjectsListItemTag: @@ -129,6 +157,22 @@ private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) } } + /// + /// Gets the theme helper. + /// + /// The Theme helper. + private ThemeHelper GetThemeHelper() + { + if (this.themeHelper != null) + { + return this.themeHelper; + } + + this.themeHelper = new ThemeHelper(); + this.themeHelper.Initialize(); + return this.themeHelper; + } + /// /// Handles the Closing event of the Window control. ///