繁体   English   中英

WPF造型颜色

[英]WPF Styling Colors

我想做这样的事情:

资源字典

<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'.

无法将其钉牢,任何人都能指出正确的方向吗?

BackgroundBrush ,而不是Color 您最好的选择是将“主要”和“次要”资源定义为画笔而不是颜色。

很确定你甚至可以将刷子从你现有的颜色上移开。

<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource clrPrimary}" />
...
    <Setter Property="Background" Value="{StaticResource PrimaryBrush}" />

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM