Skip to content

Commit 7e9da83

Browse files
fix(Theme): Fixed the theme toggle button for windows and WASM (#592)
1 parent 87de877 commit 7e9da83

File tree

1 file changed

+26
-14
lines changed
  • samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared

1 file changed

+26
-14
lines changed

samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Shell.xaml.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,34 @@ private void InitializeSafeArea()
102102

103103
private void ToggleButton_Click(object sender, RoutedEventArgs e)
104104
{
105-
// Set theme for window root.
106-
if (DarkModeToggle.IsChecked is { } value)
105+
if (this.XamlRoot.Content is FrameworkElement root)
107106
{
108-
SystemThemeHelper.SetApplicationTheme(darkMode: value);
109-
}
110-
else
111-
{
112-
SystemThemeHelper.ToggleApplicationTheme();
113-
DarkModeToggle.IsChecked = SystemThemeHelper.IsAppInDarkMode();
114-
}
107+
switch (root.ActualTheme)
108+
{
109+
case ElementTheme.Default:
110+
if (SystemThemeHelper.GetCurrentOsTheme() == ApplicationTheme.Dark)
111+
{
112+
root.RequestedTheme = ElementTheme.Light;
113+
}
114+
else
115+
{
116+
root.RequestedTheme = ElementTheme.Dark;
117+
}
118+
break;
119+
case ElementTheme.Light:
120+
root.RequestedTheme = ElementTheme.Dark;
121+
break;
122+
case ElementTheme.Dark:
123+
root.RequestedTheme = ElementTheme.Light;
124+
break;
125+
}
115126

116-
if (NavigationViewControl.PaneDisplayMode == MUXC.NavigationViewPaneDisplayMode.LeftMinimal)
117-
{
118-
// Close navigation view when changing the theme
119-
// to allow the user to see the difference between the themes.
120-
NavigationViewControl.IsPaneOpen = false;
127+
if (NavigationViewControl.PaneDisplayMode == MUXC.NavigationViewPaneDisplayMode.LeftMinimal)
128+
{
129+
// Close navigation view when changing the theme
130+
// to allow the user to see the difference between the themes.
131+
NavigationViewControl.IsPaneOpen = false;
132+
}
121133
}
122134
}
123135

0 commit comments

Comments
 (0)