I have the usual style:
<Style TargetType="{x:Type DataGrid}">
<Setter Property="ColumnHeaderStyle">
<Setter.Value>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="{x:Null}" /> <!-- this doesn't help, either -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Border Background="SomeTransparentColor" CornerRadius="20" Margin="5" />
...
The problem is that the background is applied twice: once for all the headers together, for the complete header row, and once for each of the headers separately. Because I use a partly transparent color, this looks rather ugly.
How can I keep WPF from applying this style to the whole header row background as well?
The Default style of the DataGrid column Header puts one layout below of all column headers having the same style as the column headers. This base layer is added so that the header area visibly fills up the full horizontal space even if the sum of all column headers is smaller. The following style changes the approach but keeps the requirement and removes the base layer:
<Style TargetType="{x:Type DataGridColumnHeadersPresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeadersPresenter}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<ItemsPresenter />
<DataGridColumnHeader x:Name="PART_FillerColumnHeader"
Grid.Column="1"
IsHitTestVisible="False" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>