Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法覆盖标签';WPF中的s风格_Wpf - Fatal编程技术网

无法覆盖标签';WPF中的s风格

无法覆盖标签';WPF中的s风格,wpf,Wpf,我在App.xaml中定义了标签的样式 <Application.Resources> <ResourceDictionary> <Style TargetType="Label" > <Setter Property="Foreground" Value="Blue"/> </Style> <Style TargetType="TextBlock"

我在App.xaml中定义了标签的样式

 <Application.Resources>
    <ResourceDictionary>
        <Style TargetType="Label" >
            <Setter Property="Foreground" Value="Blue"/>
        </Style>
        <Style TargetType="TextBlock" >
            <Setter Property="Foreground" Value="Blue"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>

预先应用于my Main Window.xaml中标签控件的样式。但当我试图在控件上显式设置前景时,它不起作用(我想知道)。App.xaml中定义的颜色仍然适用(仅适用于标签)



同样的逻辑适用于Textblock和所有控件。有什么建议吗?

由于文本块的样式设置,您的
标签的
前景将以蓝色显示

<Style TargetType="TextBlock" >
    <Setter Property="Foreground" Value="Blue"/>
</Style>

您可以在中查看有关此的更多详细信息


由于文本块的样式设置,您的
标签的
前景将以蓝色显示

<Style TargetType="TextBlock" >
    <Setter Property="Foreground" Value="Blue"/>
</Style>

您可以在中查看有关此的更多详细信息


这是一种解释,但不是解决办法;)



如果像这样定义样式,则还可以在网格中设置/覆盖标签前景。因此,这些Styles默认标签和文本块为黑色,但如果您愿意,可以更改为蓝色。

这是一种解释,但不是解决方案;)


如果像这样定义样式,则还可以在网格中设置/覆盖标签前景。因此,这些手写体默认标签和文本块为黑色,但如果您愿意,可以更改为蓝色

<Style TargetType="{x:Type TextBlock}">
    <Setter Property="FontFamily"
            Value="Tahoma" />
    <Setter Property="FontSize"
            Value="{StaticResource StandardFontSize}" />
    <Setter Property="Foreground"
            Value="Black" />
    <Setter Property="VerticalAlignment"
            Value="Center" />
    <Setter Property="HorizontalAlignment"
            Value="Left" />
</Style>    
<Style TargetType="{x:Type Label}">
    <Setter Property="Foreground"
            Value="Black" />
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <TextBlock Text="{Binding}"
                           Foreground="{Binding RelativeSource={RelativeSource AncestorType=Label}, Path=Foreground}" />
            </DataTemplate>
        </Setter.Value>
    </Setter>            
</Style>