Skip to content

Commit

Permalink
fix(Theme): Fixed the theme toggle button for windows and WASM (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Antoine-Soucy committed Jun 12, 2023
1 parent 87de877 commit 7e9da83
Showing 1 changed file with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,34 @@ private void InitializeSafeArea()

private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
// Set theme for window root.
if (DarkModeToggle.IsChecked is { } value)
if (this.XamlRoot.Content is FrameworkElement root)
{
SystemThemeHelper.SetApplicationTheme(darkMode: value);
}
else
{
SystemThemeHelper.ToggleApplicationTheme();
DarkModeToggle.IsChecked = SystemThemeHelper.IsAppInDarkMode();
}
switch (root.ActualTheme)
{
case ElementTheme.Default:
if (SystemThemeHelper.GetCurrentOsTheme() == ApplicationTheme.Dark)
{
root.RequestedTheme = ElementTheme.Light;
}
else
{
root.RequestedTheme = ElementTheme.Dark;
}
break;
case ElementTheme.Light:
root.RequestedTheme = ElementTheme.Dark;
break;
case ElementTheme.Dark:
root.RequestedTheme = ElementTheme.Light;
break;
}

if (NavigationViewControl.PaneDisplayMode == MUXC.NavigationViewPaneDisplayMode.LeftMinimal)
{
// Close navigation view when changing the theme
// to allow the user to see the difference between the themes.
NavigationViewControl.IsPaneOpen = false;
if (NavigationViewControl.PaneDisplayMode == MUXC.NavigationViewPaneDisplayMode.LeftMinimal)
{
// Close navigation view when changing the theme
// to allow the user to see the difference between the themes.
NavigationViewControl.IsPaneOpen = false;
}
}
}

Expand Down

0 comments on commit 7e9da83

Please sign in to comment.