WPF 数据网格所选行的背景颜色

WPF Data grid Background color of selected row

我想设置所选行的背景颜色。请看下面的代码。 前景颜色(文本颜色)有效,但它不会改变行的背景颜色。

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Grid>
                    <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="DataGridCell.IsSelected" Value="True">
            <Setter Property="Foreground" Value="Blue" />
            <Setter Property="Background" Value="Green" />
        </Trigger>
    </Style.Triggers>
</Style>


<DataGrid x:Name="Details" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10"
          ItemsSource="{Binding Details}" >
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Index}" Header="Index" />
        <DataGridTextColumn Binding="{Binding One}" Header="1" />
        <DataGridTextColumn Binding="{Binding two}" Header="2" />
        <DataGridTextColumn Binding="{Binding three}" Header="3" />
    </DataGrid.Columns>
</DataGrid>

现在,为行本身添加特定样式后问题已解决。当我为单元格添加时它不起作用。

    <Style TargetType="{x:Type DataGridRow}">
    <Style.Triggers>
        <Trigger Property="DataGridRow.IsSelected" Value="True">
            <Setter Property="Foreground" Value="Blue" />
            <Setter Property="Background" Value="Green" />
        </Trigger>
    </Style.Triggers>
</Style>