你尝试过的应该确实有效。
看这个例子:
<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="10*"/>
</Grid.RowDefinitions>
<Rectangle Fill="#FF0090FF"/>
<DataGrid Grid.Row="1" ItemsSource="{Binding TestCollection}" Background="Purple">
<DataGrid.Resources>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="Yellow"/>
</Style>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#6F0090FF"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
</DataGrid>
</Grid>
有蓝色矩形。将Fill 属性设置为#FF0090FF。您应该注意的是,您所称的"UnSelected Background color" 实际上是Background 的DataGridRow。
现在...所选单元格的背景颜色与该矩形的Fill (#0090FF) 完全相同。我只将Alpha 更改为大约 50%(#6F0090FF)。你所看到的就是你所期望的绿色。
更新
当您想保留Background 或DataGridCell 时,您必须选择不同的方法。我建议在您的DataGridCell's ControlTemplate 中再创建一层
这个层...我们可以称之为例如 "selectedCellVisual" 只有当单元格被选中时才可见。
所以...我们必须创建ControlTemplate,因此我们必须更改前面示例中DataGridCell 的样式。
<Style TargetType="DataGridCell" >
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Background" Value="Red"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid>
<Rectangle x:Name="selectedCellVisual" Fill="#6F0090FF" Visibility="Collapsed"/>
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="selectedCellVisual" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在DataGridCell 有红色Background,当它被选中时,半透明的蓝色矩形“selectedCellVisual” 可见。背景上的透明蓝色和红色是最终的紫罗兰色。
你应该注意
<Setter Property="OverridesDefaultStyle" Value="True"/>
它必须在那里...因为我们没有更改 IsSelected 属性的触发器,该属性会更改单元格的背景。
它以默认样式定义。它会更改 Background 和 Foreground 属性。您可以在第一个示例中注意到这一点。前景设置为白色,单元格周围有一像素宽的蓝线。