0

I am trying to make my UWP (Windows 10) application to have option for dynamic theme change.

I have added a toggle button, that should toggle dark/light theme. But I have managed to change only on the current page, as soon as I navigate to other page the theme is returned to default one. The code goes like this:

RequestedTheme = toggleButton.IsChecked.Value ? ElementTheme.Light : ElementTheme.Dark;

Also, I would like to make my own light and dark theme.

Is there any easy solution for this?

Thanks

Decade Moon
  • 32,968
  • 8
  • 81
  • 101
user3239349
  • 877
  • 1
  • 12
  • 33
  • 3
    If you want to change the theme in real time, without restarting your app, you should change the theme of app's rootFrame. `((Frame)Window.Current.Content).RequestedTheme = toggleButton.IsChecked.Value ? ElementTheme.Light : ElementTheme.Dark;` – Marian Dolinský Jan 04 '17 at 11:28
  • Thank you, this solved that. Just another question, how can I customize styles? For example, how to make custom colors for Dark style? – user3239349 Jan 04 '17 at 12:38
  • You have to create custom resource dictionaries for each theme. Take a look [here](https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/resourcedictionary-and-xaml-resource-references#theme-resources-and-theme-dictionaries). – Marian Dolinský Jan 04 '17 at 12:51

1 Answers1

0

instead of changing the RequestTheme on the page object use the App. App.Current.RequestTheme = toggleButton.IsChecked.Value ? ElementTheme.Light : ElementTheme.Dark;

see Changing Theme in Windows 10 UWP App Programmatically

Community
  • 1
  • 1
Dave Smits
  • 1,871
  • 14
  • 22