WPF使用资源中的文本颜色

我有一个名为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}" />
RENXIAODUO87 回答:WPF使用资源中的文本颜色

如评论中所述,ForegroundSolidColorBrush而不是颜色。所以改变:

<Color x:Key="TextColor1">#696969</Color>

对此:

<SolidColorBrush x:Key="TextColor1" Color="#696969"/>
本文链接:https://www.f2er.com/3128557.html

大家都在问