I want to do something like this:
<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>
'#FF5381AC' is not a valid value for property 'Background'.
Having trouble nailing it down, can any one point me in the right direction?
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}" />
The background property needs a brush to work.
<Window.Resources>
<SolidColorBrush x:Key="clrPrimary" Color="#5381ac" />
</Window.Resources>
Background属性的类型为System.Windows.Media.Brush
,而不是Color。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.