【发布时间】:2015-01-23 06:43:18
【问题描述】:
我有一个简单的DataGrid,我想在其中设置所选行的样式并将文本居中。我尝试了以下方法,但它不起作用:
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
为什么以上不能一起工作?如果我移除触发器,它将居中,但不会使用我想要的颜色。
【问题讨论】: