此标题栏文本颜色根据当前选择的系统颜色在黑色和白色之间变化(白色文本在深色背景上,黑色文本在浅色背景上)
那个颜色的 ThemeResource
是什么?
我有一个 background
设置为 SystemControlBackgroundAccentBrush
的按钮,我想根据需要调整 foreground
(字体颜色)在当前选择的口音上。
我试过 SystemControlForegroundAccentBrush
但看起来这和 SystemControlBackgroundAccentBrush
是相同的颜色(而且我没有在系统设置中更改任何内容)。
最佳答案
没有一种画笔可以解决这个问题。
Avoid using the accent color as a background, especially for text and icons. Because the accent color can change, if you must use it as a background, there’s some additional work you must do to ensure that foreground text is easy to read. (Source: UWP Style Guide)
基于他们建议在文档中使用的示例算法,这应该可以解决问题:
private void UpdateAccentColorForeground(FrameworkElement element)
{
var uiSettings = new UISettings();
Color c = uiSettings.GetColorValue(UIColorType.Accent);
element.RequestedTheme = ((5 * c.G + 2 * c.R + c.B) <= 8 * 128)
? ElementTheme.Light
: ElementTheme.Dark;
}
关于c# - 窗口标题文本颜色的主题资源是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38152470/