我正在尝试更改 WPF DataGrid 控件的选定单元格的样式。
styleDataGridCell
和 和有什么不一样DataGridRow
?我在下面尝试了各种组合,它们都有效。但是,似乎我只需要设置样式或 。DataGridCell
DataGridRow
两者兼有的目的是什么?这告诉我我误解了他们的目的。
样式DataGridCell
:(在我自己的代码中,我更改了默认颜色)
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
</Style.Triggers>
</Style>
样式DataGridRow
:(在我自己的代码中,我更改了默认颜色)
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
</Style.Triggers>
</Style>