2013-10-19 1 views
1

전역으로 정의 텍스트 블록 헤더 셀의 전경 속성을 재정의하는 방법을WPF는 : XAML에 전역으로 정의 텍스트 블록 그레이 색상의

<Style TargetType="{x:Type TextBlock}"> 
    <Setter Property="Foreground" Value="{StaticResource BR_SE_Gray}" /> 
    <Setter Property="TextTrimming" Value="CharacterEllipsis"/> 
    <Setter Property="FontSize" Value="11"/> 
    <Setter Property="FontFamily" Value="Arial Unicode MS"/> 
    <Style.Triggers> 
     <Trigger Property="controls:TextBlockService.IsTextTrimmed" Value="True"> 
      <Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/> 
     </Trigger> 
    </Style.Triggers> 

이 난에서 그리드 뷰 헤더 셀 블랙 색상을 원하는 아래에 언급 된 코드. 위 코드 블록에서 foreground 속성에 검정색을 원합니다. 전역 적으로 정의 된 텍스트 블록 색상은 회색입니다. 그것을 무시하고

<ContentControl x:Name="ContentPresenter" 
    Grid.Column="0" 
    Margin="{TemplateBinding Padding}" 
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
    Content="{TemplateBinding Content}" 
    ContentTemplate="{TemplateBinding ContentTemplate}" 
    FontFamily="pack://application:,,,/Themes/#Arial Rounded MT Bold" 
    FontWeight="Bold" 
    Foreground="{TemplateBinding Foreground}" 
    IsTabStop="{TemplateBinding IsTabStop}"> 

    <ContentControl.Style> 
     <Style TargetType="{x:Type ContentControl}"> 
      <Setter Property="FontSize" Value="8" /> 
      <Setter Property="FontWeight" Value="Bold" /> 
      <Setter Property="FontFamily" Value="pack://application:,,,/Themes/#Arial Rounded MT Bold" /> 
      <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
      <Setter Property="VerticalContentAlignment" Value="Stretch" /> 
     </Style> 
    </ContentControl.Style> 

+3

\ 대신 전경 =의 예를 원하는 값 "{TemplateBinding 전경을}"로 설정 - 스타일 inherit other properties set in base style

당신이 스타일을 위해 BasedOn을 설정해야합니다 그래서 직접 포어 그라운드 = "블랙" – Nitin

답변

1

리소스 resolved by traversing up logical tree있는 아래 코드는 블랙 만들려면. 따라서 override resource ContentControl의 resource 섹션 아래 textBlock에 대한 리소스를 지정하고 ForegroundBlack으로 설정하면됩니다.

이렇게하면 new style will get applied to all the textBlocks falling under ContentControl과 ContentControl 외부에있는 textBoxes는 전역 스타일을 계속 사용합니다.

대신 templateparent하는 전경 바인딩의 당신은 ContentControl에서
<ContentControl> 
    <ContentControl.Resources> 
     <Style TargetType="{x:Type TextBlock}" 
      BasedOn="{StaticResource {x:Type TextBlock}}"> 
      <Setter Property="Foreground" Value="Black" /> 
     </Style> 
    </ContentControl.Resources> 
</ContentControl>