나는 다음과 같은 체크 박스를기본 TextBlock의 스타일
<CheckBox x:Name="checkBox" Content="CheckBox" Width="74"/>
을하고 난 버튼 내가 TextBlock에 대해 "기본"색상을 설정할
<Button Name="TestButton" Content="Test" />
있습니다. 나는 달성이 다음과 같은 내용을 가지고있는 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
편집 : ResourceDictionaries이 같은 Application.xaml에 정의되어 있습니다
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TextBlock.xaml"/>
<ResourceDictionary Source="Buttons.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
ContentPresenter에서'TextBlock.Foreground' 대신'TextElement.Foreground = "Black"을 시도 했습니까? –
그래,'TextElement.Foreground'와'TextBlock.Foreground' 둘 다 Text의 색깔을 바꾸지 만 여전히 슬프게도 Other 스타일로 덮어 씁니다. – Splinti
'ContentPresenter.Resources'에서 또 다른 기본 TextBlock 스타일을 정의하는 방법은 무엇입니까? –