Skip to content

Commit

Permalink
Workaround for a problem with apply of dark theme.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krzysztof-lorenc committed Apr 9, 2019
1 parent f04d064 commit e64b1dd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
18 changes: 4 additions & 14 deletions src/Soloplan.WhatsON.GUI/Config/MainConfigPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public partial class MainConfigPage : Page
/// <summary>
/// The Theme helper.
/// </summary>
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();
}
Expand Down Expand Up @@ -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);
}

/// <summary>
/// Gets the theme helper.
/// </summary>
/// <returns>The Theme helper.</returns>
private ThemeHelper GetThemeHelper()
{
return this.themeHelper ?? (this.themeHelper = new ThemeHelper());
this.themeHelper.ApplyLightDarkMode(isDark);
}
}
}
46 changes: 45 additions & 1 deletion src/Soloplan.WhatsON.GUI/Config/View/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public partial class ConfigWindow : Window
/// </summary>
private AboutPage aboutPage;

/// <summary>
/// The Theme helper.
/// </summary>
private ThemeHelper themeHelper;

/// <summary>
/// The window shown flag.
/// </summary>
private bool windowShown;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigWindow"/> class.
/// </summary>
Expand All @@ -84,6 +94,24 @@ public ConfigWindow(ApplicationConfiguration configuration)
/// </summary>
public event EventHandler<EventArgs> ConfigurationApplying;

/// <summary>
/// Raises the <see cref="E:ContentRendered" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);

if (this.windowShown)
{
return;
}

this.windowShown = true;

this.GetThemeHelper().ApplyLightDarkMode(this.configurationSource.DarkThemeEnabled);
}

/// <summary>
/// Handles the SelectionChanged event of the ListBox control.
/// </summary>
Expand Down Expand Up @@ -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:
Expand All @@ -129,6 +157,22 @@ private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
}
}

/// <summary>
/// Gets the theme helper.
/// </summary>
/// <returns>The Theme helper.</returns>
private ThemeHelper GetThemeHelper()
{
if (this.themeHelper != null)
{
return this.themeHelper;
}

this.themeHelper = new ThemeHelper();
this.themeHelper.Initialize();
return this.themeHelper;
}

/// <summary>
/// Handles the Closing event of the Window control.
/// </summary>
Expand Down

0 comments on commit e64b1dd

Please sign in to comment.