DataGrid Header loses fluent styling when HorizontalContentAlignment property applied
Description
DataGrid Header loses fluent styling when HorizontalContentAlignment property applied Without any props on the datagrid header the header style is ok :
<Window.Resources>
<!--<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>-->
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
once
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
is enabled:
only the header becomes light theme
Reproduction Steps
use this with a datagrid that has column headers and toggle the disabled prop:
<Window.Resources>
<!--<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>-->
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
maybe relevant .csproj:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<UseWindowsForms>False</UseWindowsForms>
<StartupObject></StartupObject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);WPF0001</NoWarn>
<ApplicationIcon>Properties\icon.ico</ApplicationIcon>
</PropertyGroup>
this is how I'm applying the theme:
public MainWindow() {
InitializeComponent();
Application.Current.ThemeMode = ThemeMode.System;
//...
}
Expected behavior
The header should remain in dark mode, even if the text is centered. Works just fine for the datagrid cells, only the headers break.
Actual behavior
Header goes to light theme, no errors that I've seen.
Regression?
No response
Known Workarounds
No response
Impact
No response
Configuration
dotnet --version
9.0.101
systeminfo:
systeminfo
Host Name:
OS Name: Microsoft Windows 11 Business
OS Version: 10.0.26100 N/A Build 26100
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Workstation
OS Build Type: Multiprocessor Free
System Manufacturer: Dell Inc.
System Model: Precision 5770
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 154 Stepping 3 GenuineIntel ~2400 Mhz
BIOS Version: Dell Inc. 1.28.0, 9/26/2024
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC-08:00) Pacific Time (US & Canada)
Total Physical Memory: 32,453 MB
Available Physical Memory: 10,831 MB
Virtual Memory: Max Size: 44,229 MB
Virtual Memory: Available: 16,083 MB
Virtual Memory: In Use: 28,146 MB
Page File Location(s): C:\pagefile.sys
Logon Server: \\SERVER-ST-1
Hotfix(s): 4 Hotfix(s) Installed.
[01]: KB5054979
[02]: KB5058411
[03]: KB5058538
[04]: KB5058523
Virtualization-based security: Status: Running
Required Security Properties:
Available Security Properties:
Base Virtualization Support
Secure Boot
DMA Protection
UEFI Code Readonly
SMM Security Mitigations 1.0
Mode Based Execution Control
APIC Virtualization
Services Configured:
Hypervisor enforced Code Integrity
Services Running:
Hypervisor enforced Code Integrity
Hypervisor-Enforced Paging Translation
App Control for Business policy: Enforced
App Control for Business user mode policy: Off
Security Features Enabled:
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
Other information
On light theme, it seems to be a slightly different control object (has highlighting on select, has arrows)
the sorting arrows work on light theme, but not dark. My guess is that it might be falling back to light theme because the dark ones are missing certain properties?
I just ran into the same problem, any updates ?
I'm also experiencing the same behaviour if I Bind the IsEnabled property of the DataGrid. While it switches to the default style for when IsEnabled = false, it looses the Fluent style