How can I detect Windows 10 light/dark mode?

后端 未结 6 566
情话喂你
情话喂你 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条回答
  •  萌比男神i
    2020-12-03 16:01

    I have found an easier solution, which should work in JavaScript apps as well, without requiring the Windows Runtime Component - the UISettings class:

    var uiSettings = new Windows.UI.ViewManagement.UISettings();
    var color = uiSettings.getColorValue(
                            Windows.UI.ViewManagement.UIColorType.background
                           );
    

    The color you get is either black for dark theme or white for light theme.

    The class also has very useful event ColorValuesChanged which you can use to observe theme changes at runtime.

提交回复
热议问题