Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Styling Colors

I want to do something like this:

Resource Dictionary

<Color x:Key="clrPrimary">#5381ac</Color>
<Color x:Key="clrSecondary">#20558a</Color>

<Style TargetType="Grid" x:Key="myGrid">
    <Setter Property="Background" Value="{StaticResource clrPrimary"/>
</Style>

Getting Exception:

'#FF5381AC' is not a valid value for property 'Background'.

Having trouble nailing it down, can any one point me in the right direction?

like image 572
AGoodDisplayName Avatar asked Mar 12 '12 21:03

AGoodDisplayName


1 Answers

Background is a Brush, not a Color. Your best bet is to define your "Primary" and "Secondary" resources as brushes rather than colours.

Pretty sure you could even base the brushes off your existing colours.

<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource clrPrimary}" />
...
    <Setter Property="Background" Value="{StaticResource PrimaryBrush}" />
like image 194
Matt Hamilton Avatar answered Oct 12 '22 02:10

Matt Hamilton