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)
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).
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.
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.
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With