Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Theme): Fixed the theme toggle button for windows and WASM #592

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading