如何了解 Windows 10 周年更新或更高版本是否在 WPF 应用程序中使用其浅色或深色主题? [英] How can I get whether Windows 10 Anniversary Update or later is using its light or dark theme in a WPF app?

查看:26
本文介绍了如何了解 Windows 10 周年更新或更高版本是否在 WPF 应用程序中使用其浅色或深色主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 WPF 桌面应用程序,我想使用桌面桥将其放入 Windows 应用商店.该应用程序能够在明暗模式下展示自己,并使用强调色.但是,为了成为 Windows 10 的好公民,如果可能的话,我想从操作系统中获取这些信息.

I have written a WPF desktop app that I want to put in the Windows Store using the Desktop Bridge. The app is capable of presenting itself in light and dark modes, and using an accent color. But, to be a good citizen of Windows 10, I want to get that information from the OS, if possible.

据我目前的理解,我可以从这里获得强调色:

It is my current understanding that I can get the accent color from here:

var accentBrush = SystemParameters.WindowGlassBrush;

如何了解 Windows 10 是采用浅色还是深色主题?此外,您建议采用什么方法来通知用户对浅色/深色或强调色的偏好发生变化?

How can I get whether Windows 10 is in its light or dark theme? Also, what method would you recommend to be notified of a change in the user's preference for either light/dark or the accent color?

推荐答案

每当 Windows 10 周年更新或更高版本中的此明/暗模式设置发生更改时,都会更新一个注册表值.关键是:

There is a registry value that is updated whenever this light/dark mode setting in Windows 10 Anniversary Update or later changes. It's key is:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize

值的名称是:

AppsUseLightTheme

如果为 1,则主题为 Light.如果为 0,则主题为 Dark.如果我找不到键或值(就像在以前版本的 Windows 中一样),我将假定为 Light.

If it is 1, then the theme is Light. If it is 0, then the theme is Dark. I'm going to assume Light if I can't find the key or the value (as would be the case in previous versions of Windows).

就我而言,lindexi 的答案值得称赞.没有那个评论,我没有想到要调查.

As far as I'm concerned, lindexi deserves credit for the answer. Without that comment, it didn't occur to me to investigate.

这篇关于如何了解 Windows 10 周年更新或更高版本是否在 WPF 应用程序中使用其浅色或深色主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆