[英]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? 无法将其钉牢,任何人都能指出正确的方向吗?
Background
is a Brush
, not a Color
. Background
是Brush
,而不是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. background属性需要刷子才能工作。
<Window.Resources>
<SolidColorBrush x:Key="clrPrimary" Color="#5381ac" />
</Window.Resources>
Background属性的类型为System.Windows.Media.Brush
,而不是Color。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.