DataGridExtensions icon indicating copy to clipboard operation
DataGridExtensions copied to clipboard

DataGrid column header style not congruent with .NET 9 / Win 11 styles

Open fraluderin opened this issue 1 year ago • 4 comments

I have a simple window with a DataGrid inside. The project is targeting .NET 9 and Win 11 theming is enabled by adding the resources in App.xaml file:

  <Application.Resources>
      <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
              <ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml" />
          </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
  </Application.Resources>

Column headers are displayed without taking into account the Win 11 styling.

Current behavior:

Image

Expected behavior (I got this by removing dgx:DataGridFilter.IsAutoFilterEnabled="True" from my DataGrid XAML):

Image

Note that the headers are displayed but the lack of contrast make them almost unreadable. I'm opening this issue, but I'm ready to forward it to WPF repo if this is not a DataGridExtension-related issue.

fraluderin avatar Dec 09 '24 14:12 fraluderin

If you use custom styles for the data grid, you must use custom styles for the headers, too

tom-englert avatar Dec 09 '24 15:12 tom-englert

So this could be an issue from the Win 11 style pack I added in my resources? Should I report this in WPF repo?

fraluderin avatar Dec 11 '24 07:12 fraluderin

Even if this custom styles are provided by WPF, they are still custom styles, affecting only the controls included in these custom styles.

DGX styles rely on the SystemColors, which are usually not updated by such custom style components - you have to do it by your own: https://github.com/dotnet/DataGridExtensions/blob/a8b0e4aee70bbedcd1831b5b28eee3abd9a7ae83/src/DataGridExtensions/Themes/Generic.xaml#L241-L245

See e.g. here: https://github.com/icsharpcode/ILSpy/blob/e652490cce4a3f5ec54b9c858807418f02e39ae0/ILSpy/Themes/Base.Dark.xaml#L41-L49

tom-englert avatar Dec 11 '24 09:12 tom-englert

I am using MahApps.Metro and needed this default style everywhere for old .NET 4.6.2 target:

<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MahApps.Styles.DataGridColumnHeader}"/>

For .NET 8 I did not require it anymore though (no idea why), at least so far.

Brains avatar Jan 08 '25 18:01 Brains