我有一个颜色称为Colors.xaml的文件
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ErgoRythm">
<Color x:Key="TextColor1">#696969</Color>
</ResourceDictionary>
在我的App.xaml中,有
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="CustomStyles" Source="Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
[现在我想将颜色添加到文本中,但是得到一个'资源“ TextColor1”具有不兼容的类型。'当我使用
<Label Grid.Row="0" Content="Genearal Volume" Grid.Column="0" FontSize="20" Foreground="{DynamicResource TextColor1}" />
如注释中所述,Foreground
是SolidColorBrush
不是颜色。因此更改:
<Color x:Key="TextColor1">#696969</Color>
对此:
<SolidColorBrush x:Key="TextColor1" Color="#696969"/>