DataGridCell.Template Style overriding IsSelected Trigger
Why does the IsSelected Trigger below only work when Template Setter is absent from the code? How can I get both to function as expected?
I have the following in my Application.Resources tag;
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
&l开发者_如何学JAVAt;ContentPresenter VerticalAlignment="Center"></ContentPresenter>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
When you re-template the DataGridCell you also lose the border that is actually the control that draws the Background. Add this and it'll work.
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center"></ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
精彩评论