小编Jaw*_*har的帖子

无法覆盖WPF中的标签样式

我在App.xaml中为Label定义了一个样式.

 <Application.Resources>
    <ResourceDictionary>
        <Style TargetType="Label" >
            <Setter Property="Foreground" Value="Blue"/>
        </Style>
        <Style TargetType="TextBlock" >
            <Setter Property="Foreground" Value="Blue"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

样式适用于我的MainWindow.xaml中的标签Control.但是当我试图在控件上明确设置Foreground时,它不起作用(我不知道).App.xaml中定义的颜色仍在应用(仅适用于Label).

<Grid>
    <Label Content="Label" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <TextBlock Text="TextBlock" Foreground="Black" VerticalAlignment="Bottom" Height="15.96" Margin="257.537,0,270.003,86" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

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

wpf

1
推荐指数
2
解决办法
2717
查看次数

标签 统计

wpf ×1