如何检测 Windows 10 亮/暗模式? [英] How can I detect Windows 10 light/dark mode?
问题描述
我正在使用 Windows.UI.ViewManagement.UISettings
来获取系统强调色,但该类似乎没有任何用于亮/暗模式的方法或属性.我找不到有关此功能的文档,如何检测?
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 failed to find a document for this feature, how can I detect this?
PS:我正在制作一个无法访问 Windows.UI.Xaml
命名空间的 JS 应用.
PS: I'm making a JS app which does not have access for Windows.UI.Xaml
namespace.
推荐答案
我找到了一个更简单的解决方案,它也适用于 JavaScript 应用程序,无需 Windows 运行时组件 - UISettings
类:
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
);
深色主题的黑色或浅色主题的白色颜色.
该类还有非常有用的事件 ColorValuesChanged
,您可以使用它在运行时观察主题变化.
The class also has very useful event ColorValuesChanged
which you can use to observe theme changes at runtime.
这篇关于如何检测 Windows 10 亮/暗模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!