How can I detect Windows 10 light/dark mode?

后端 未结 6 538
情话喂你
情话喂你 2020-12-03 15:12

I\'m using Windows.UI.ViewManagement.UISettings to get system accent color but it seems this class does not have any method or property for light/dark mode. I f

6条回答
  •  情深已故
    2020-12-03 16:00

    Before the Windows Anniversary update you could not do that. The application theme was always the one you set in the App.xaml file:

    
    
    

    Now with the new Anniversary Update, you can remove this line from the App.xaml file, which will make the app honor the user's system settings.

    The RequestedTheme enumeration has actually three values - Dark, Light and Default. Default is the value that reflects the system settings, Dark and Light force the theme.

    If you want to actually detect the current theme in code when App's RequestedTheme is Default, you will probably need to check the some color resource like SystemAltHighColor for its value, because that will give you an idea of what theme is currently set.

提交回复
热议问题