2016-10-12 3 views
0

나는 다음과 같은 체크 박스를기본 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> 
+0

ContentPresenter에서'TextBlock.Foreground' 대신'TextElement.Foreground = "Black"을 시도 했습니까? –

+0

그래,'TextElement.Foreground'와'TextBlock.Foreground' 둘 다 Text의 색깔을 바꾸지 만 여전히 슬프게도 Other 스타일로 덮어 씁니다. – Splinti

+0

'ContentPresenter.Resources'에서 또 다른 기본 TextBlock 스타일을 정의하는 방법은 무엇입니까? –

답변

1

당신 그 Resources 다른 하나를 정의하여 ContentPresenter에 대한 로컬 기본 TextBlock 스타일을 재정의하는 시도 할 수 :

<ContentPresenter ... > 
    <ContentPresenter.Resources> 
     <Style TargetType="TextBlock"> 
      <Setter Property="Foreground" Value="Black" /> 
     </Style> 
    </ContentPresenter.Resources> 
</ContentPresenter> 

그러나 기본 컨트롤 텍스트 색상을 설정할 수있는 더 좋은 방법은 App.Resources이 같다. TextElement.Foreground은 주어진 개별 요소에서이를 대체합니다.

<SolidColorBrush 
    x:Key="{x:Static SystemColors.ControlTextBrushKey}" 
    Color="White" 
    /> 

당신이 사용하고 기본 TextBlock 스타일을 버릴 경우, 당신이 그것을 가지고로 ContentPresenter 작동합니다 원본.