[英]How to monitor for a system color change in a WinUI 3 application
If I have a WinUI 3 application that is executing, and I change the Color setting from Light to Dark in the Settings/Personalization/Colors dialog, how can I detect this change in the WinUI 3 application?如果我有一个正在执行的 WinUI 3 应用程序,并且我在设置/个性化/颜色对话框中将颜色设置从浅色更改为深色,我如何在 WinUI 3 应用程序中检测到此更改?
After rephrasing my question to UWP from WinUI 3, a satisfactory answer resulted.从 WinUI 3 将我的问题改写为 UWP 后,得到了令人满意的答案。 The UISettings class provides the solution.
UISettings class 提供了解决方案。
UISettings uiSettings = new UISettings(); UISettings uiSettings = new UISettings();
uiSettings.ColorValuesChanged += ColorValuesChanged; uiSettings.ColorValuesChanged += ColorValuesChanged;
private void ColorValuesChanged(UISettings sender, object args) { var accentColor = sender.GetColorValue(UIColorType.Accent);私人无效 ColorValuesChanged(UISettings 发件人,object 参数){ var accentColor = sender.GetColorValue(UIColorType.Accent);
var backgroundColor = sender.GetColorValue(UIColorType.Background);
} }
Thanks to Martin Zikmund for this solution:感谢 Martin Zikmund 提供的解决方案:
https://blog.mzikmund.com/2017/01/observing-system-color-changes-in-uwp-apps/ https://blog.mzikmund.com/2017/01/observing-system-color-changes-in-uwp-apps/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.