简体   繁体   English

Windows系统强调颜色更改后如何更新WinJS UWP应用

[英]How to update a WinJS UWP app after the Windows system accent color changes

I have 2 variables, accentColor , and backgroundColor . 我有2个变量accentColorbackgroundColor backgroundColor updates as expected when I change the Windows settings from Light to Dark mode, but accentColor does not change when I choose a new Windows accent color. 当我将Windows设置从浅模式更改为暗模式时, backgroundColor按预期更新,但是当我选择新的Windows强调颜色时, accentColor不会改变。

var uiSettings = new Windows.UI.ViewManagement.UISettings(),
   accentColor = uiSettings.getColorValue(Windows.UI.ViewManagement.UIColorType.accent),
   backgroundColor = uiSettings.getColorValue(Windows.UI.ViewManagement.UIColorType.background);

Therefore I cannot update the UI to reflect the user's choice. 因此,我无法更新UI来反映用户的选择。 Is this a bug? 这是错误吗? Is there a work around? 有没有解决的办法?

I am checking them on the visibilitychanged event. 我正在检查他们的能见度更改事件。

document.addEventListener("visibilitychange", onVisibilityChanged);

This occurs on Windows 10 Pro 1709 build 16299.309 but surprisingly works properly on Windows 10 Mobile! 这在Windows 10 Pro 1709内部版本16299.309上发生,但出人意料地在Windows 10移动版上正常工作!

You could detect the accent color changed in the colorvalueschangedevent handler of UISettings instance. 您可以在UISettings实例的colorvalueschangedevent处理程序中检测到强调的颜色。 When you change the system' theme accent color and it will be fired. 当您更改系统的主题强调色时,它将被触发。

var uiSettings = new Windows.UI.ViewManagement.UISettings();
uiSettings.addEventListener("colorvalueschanged", onColorChanged);

function onColorChanged() {

    var accentColor = uiSettings.getColorValue(Windows.UI.ViewManagement.UIColorType.accent);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM