I am trying to set the background of a template by using color I found online in HEX code:
<Color x:Key="BaseColor">#408DD2</Color>
....
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background"
Value="{StaticResource BaseColor}" />
</Trigger>
</ControlTemplate.Triggers>
The error I get is:
'#FF408DD2' is not a valid value for property 'Background'.
Border.Background
is of type System.Windows.Media.Brush
, you cannot assign a System.Windows.Media.Color
to that.
Instead, create a resource of type Brush
:
<SolidColorBrush x:Key="BaseColor" Color="#408DD2"/>
or,
have your Setter
create the Brush to be assigned to that property:
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<SolidColorBrush Color="{StaticResource BaseColor}"/>
</Setter.Value>
</Setter>
Background is of type Brush
and not Color
. So you need to provide Brush to it:
<SolidColorBrush x:Key="BaseColor" Color="#408DD2"/>
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