I'm trying to override some style-colors in Windows 10 but I cannot get it to work.
My app.xaml looks like this:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default" Source="Theme.xaml"/>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
And my Theme.xaml looks like this
<ResourceDictionary
x:Key="Default"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="ListBoxBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxFocusBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemPressedBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemSelectedForegroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemSelectedBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="FocusVisualBlackStrokeThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ScrollBarButtonForegroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ScrollBarPanningBackgroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White"/>
<SolidColorBrush x:Key="SearchBoxHitHighlightSelectedForegroundThemeBrush" Color="Red"/>
<SolidColorBrush x:Key="SearchBoxHitHighlightForegroundThemeBrush" Color="Pink"/>
However it doesn't work, it doesn't override the style anywhere.
The styles you are setting are for Windows 8 apps. The styles used by Universal Windows apps are greatly simplified.
The easiest way to find them is to add your ListBox to a page, right click on it in the designer, and select Edit Template... Create a copy of the template and look at the names used.
All of the controls now use the same brushes when possible rather than having control-specific ones.
For example, the ListBox uses the following brushes for its Foreground, Background, and BorderBrush:
- SystemControlForegroundBaseHighBrush
- SystemControlBackgroundChromeMediumLowBrush
- SystemControlForegroundBaseHighBrush
To add to Rob's answer, for those looking for a broader app-wide response, it helped me to find the full default themes, which are available in
\(Program Files)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\<SDK version>\Generic folder
of a Windows SDK installation, in themeresources.xaml.
In that is a ResourceDictionary for Default, HighContrast, and Light. The default key handles the Dark theme in UWP, since it is what will be defaulted to when no default "Dark" ResourceDictionary is found.
The Default and Light themes have nearly 1000 control-specific colors, or more generic "SystemControlForeground..." colors like Rob showed, but in UWP they are mostly based on the following 25 color categories:
- 24 system colors
SystemAccentColor
, an OS-wide user-defined color which the UWP docs has a whole page about under Design & UI > Style > Color
- There's 6 lighter and darker shades of the above (
SystemAccentColorLight1
, ...Dark1
, etc) but they aren't used in the default resource dictionaries. However .6, .8 and .9 opacities of that color are used a handful of times, the only time opacities are used.
Then there are the 300+ color categories from Windows 8.1 that are left in, which manually pick a specific color, the extent of which you can see here
The only exception to the above is that the InkToolBar styling is almost exclusively derived from the High Contrast colors.
The High Contrast theme, pulls heavily from 8 additional System[blank]Colors that, similar to the SystemAccentColor
, are OS-wide values. They're defined by templates and/or the user if they chose a High Contrast theme, which is an option Windows 10 has in its personalization settings. High Contrast is also an accessibility feature, so I think I'll be avoiding overriding that ResourceDictionary, no matter the app branding.
But effectively, by overriding the SystemAccentColor
and the 24 System[blank]Colors in the XAML framework, you can effect the change of hundreds of specific color choices in a consistent way across an app.