我在 app.xaml 中定义了如下样式:
<Style TargetType="DataGridCell">
<Setter Property= "BorderThickness" Value="1"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Grid Height="18">
<Border BorderBrush="Black" BorderThickness=".2" >
<Border x:Name="border" Background="#992288ff" BorderBrush="Black" BorderThickness=".2">
......
......
......
</Border>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
在我的表单中,我为一个单元格定义了一种样式。代码如下:
<DataGridTextColumn Width="*" Header="Status" Binding="{Binding Status, Mode=TwoWay}" IsReadOnly="True" >
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Foreground">
<Setter.Value>
<Binding Converter="{StaticResource FGColorKey}"/>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
这里我只定义前景样式。但是我在 app.xaml 中为单元格模板定义的样式不适用于此单元格。请看下面的图片: