Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override theme brush Windows 10 UWP

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.

like image 770
robertk Avatar asked May 22 '15 08:05

robertk


1 Answers

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
like image 184
Rob Caplan - MSFT Avatar answered Oct 27 '22 08:10

Rob Caplan - MSFT