2014-11-27 5 views
0

Я хочу изменить DataGridTemplateColumn стиль контента, здесь DataGridTemplateColumn код:Изменить DataGridTemplateColumn стиль содержание

<DataGridTemplateColumn MaxWidth="50" MinWidth="30" CellStyle="{StaticResource CellStyle}"> 
<DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
     <Label Style="{StaticResource FontAwesome}" Padding="0" VerticalAlignment="Center" HorizontalAlignment="Center" Cursor="Hand" MouseLeftButtonDown="LblEdit_MouseLeftButtonDown"> 
       
     </Label> 
    </DataTemplate> 
</DataGridTemplateColumn.CellTemplate> 
</DataGridTemplateColumn> 

Вот CellStype код:

<Style x:Key="CellStyle" TargetType="DataGridCell"> 
    <Setter Property="BorderThickness" Value="0 0 1 0"/> 
    <Setter Property="BorderBrush" Value="#F6F6F6"/> 
    <Setter Property="Foreground" Value="#000"/> 
    <Setter Property="FontSize" Value="14" /> 
    <Style.Triggers> 
     <Trigger Property="DataGridCell.IsSelected" Value="True"> 
      <Setter Property="Background" Value="#FF5750" /> 
      <Setter Property="Foreground" Value="#FFFFFF" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

enter image description here

Но Ярлык в DataTemplate не эффект, когда строка выбирается, хотя другая ячейка является эффектом.

Любой способ сделать это?

Thankyou!

ответ

1

Триггер устанавливает цвет переднего плана DataGridCell, но не Label. Вы можете ссылаться на цвет переднего плана в Label, добавив к нему этот атрибут Foreground:

<Label 
    Style="{StaticResource FontAwesome}" 
    Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Control}, Path=Foreground}" 
    ... /> 
Смежные вопросы