У меня есть следующий флажокпо умолчанию TextBlock моделирование
<CheckBox x:Name="checkBox" Content="CheckBox" Width="74"/>
и у меня есть кнопка
<Button Name="TestButton" Content="Test" />
Я хочу, чтобы установить цвет "по умолчанию" для TextBlock. Я добиться того, что при наличии ResourceDictionary, который имеет следующее содержание:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White"/>
</Style>
Проблема заключается в том, что кнопка должна еще иметь черный TextBlock переднего плана, но, хотя в другом 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
Edit: в ResourceDictionaries определены в Application.xaml так:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TextBlock.xaml"/>
<ResourceDictionary Source="Buttons.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
В ContentPresenter вы пытались «TextElement.Foreground =« Черный »вместо« TextBlock.Foreground »? –
Да, 'TextElement.Foreground' и' TextBlock.Foreground' меняют цвет текста, но, к сожалению, все еще перезаписываются другим стилем. – Splinti
Как определить другой стиль TextBlock по умолчанию в ContentPresenter.Resources? –