0
我有以下的复选框默认的文本块造型
<CheckBox x:Name="checkBox" Content="CheckBox" Width="74"/>
和我有一个按钮
<Button Name="TestButton" Content="Test" />
我想设置为文本块“默认”的色彩。我做到这一点通过具有具有下列内容资源字典:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White"/>
</Style>
的问题是,该按钮还是应该有一个黑色的文字块的前景,但但在另一sourcedictionary我有以下,但仍然变为白色:
<Style TargetType="Button">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border BorderThickness="1,0,0,1" CornerRadius="5" Background="{TemplateBinding Background}">
<ContentPresenter
x:Name="ContentPresenter"
Margin="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
TextBlock.Foreground="Black"
Opacity="1.0"/>
</Border>
</ControlTemplate/>
<Setter.Value/>
</Setter>
</Style.Setters>
</Style
编辑: 的ResourceDictionaries在Application.xaml定义是这样的:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TextBlock.xaml"/>
<ResourceDictionary Source="Buttons.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
在ContentPresenter中,您是否尝试过'TextElement.Foreground =“Black”'而不是'TextBlock.Foreground'? –
是的,'TextElement.Foreground'和'TextBlock.Foreground'都改变了Text的颜色,但是仍然被其他风格所覆盖。 – Splinti
如何定义在'ContentPresenter.Resources'其他默认TextBlock的风格? –