![](/img/trans.png)
[英]WPF styling TabControl TabItems custom Foreground/Background colors
[英]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'.
無法將其釘牢,任何人都能指出正確的方向嗎?
Background
是Brush
,而不是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.