c# - 窗口标题文本颜色的主题资源是什么?

标签 c# uwp

此标题栏文本颜色根据当前选择的系统颜色在黑色和白色之间变化(白色文本在深色背景上,黑色文本在浅色背景上)

enter image description here

那个颜色的 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/

相关文章:

c# - UWP:SignTool错误:访问被拒绝。 (解决!)

c# - 动态 lambda 表达式 (OrderBy) 和可为 null 的属性类型

c# - 不聚焦,但允许互动?

C# IFilter 在解决方案中安装不正确?

C# 控制台 - 输入和删除数组

c# - Scrollviewer 中的 UWP Canvas 像鼠标输入一样处理笔输入

c# - 检测 C# 代码中的递归调用

uwp - Xamarin.Forms.UWP 数字键盘仅在软键盘上

C# UWP DataTemplate 内存泄漏

c# - UWP 将图像编码为 PNG