Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the themeResource for window's title text color?

Tags:

c#

uwp

This title bar text color changes between black and white depending on currently selected system color (white text on darker backgrounds and black text on lighter backgrounds)

enter image description here

What is the ThemeResource for that color?

I have a button with a background set to SystemControlBackgroundAccentBrush and I would like to have this effect of adjusting foreground (font color) depending on currently selected accent.


I tried SystemControlForegroundAccentBrush but it seems like this and SystemControlBackgroundAccentBrush are the same colors (and I hadn't changed anything in system settings).

like image 974
a'' Avatar asked Jul 01 '16 19:07

a''


People also ask

How to change the title bar text color in Windows 10?

To change the title bar text color in Windows 10, do the following. Open Settings. Go to Personalization - Colors. On the right, untick the option "Title bars" under "Show accent color on the following surfaces". Go to the following Registry key. See how to go to a Registry key with one click. See the string values TitleText and InactiveTitleText.

When to use themeresource references in XAML definitions?

The XAML definitions of visual states in a control template should use ThemeResource references whenever there's an underlying resource that might change because of a theme change. A system theme change won't typically also cause a visual state change.

How does the system Color Resource get the accent color?

At runtime, this resource gets the color that the user has specified as the accent color in the Windows personalization settings. While it's possible to override the system color resources, it's a best practice to respect the user's color choices, especially for contrast theme settings.

How do I know what color a brush is for each theme?

The brushes are documented in a table that tells you what color value each brush has for each of the three possible active themes. The XAML definitions of visual states in a control template should use ThemeResource references whenever there's an underlying resource that might change because of a theme change.


1 Answers

There is not a single brush that will do the trick.

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)

Building on the example algorithm they propose using in the documentation, this should do the trick:

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;
}
like image 78
David Grochocki Avatar answered Nov 15 '22 17:11

David Grochocki