Skip to content

[Fluent] Convert DataGrid ControlTheme dimension setters to DynamicResource#240

Open
dimension-zero wants to merge 1 commit into
AvaloniaUI:masterfrom
dimension-zero:master
Open

[Fluent] Convert DataGrid ControlTheme dimension setters to DynamicResource#240
dimension-zero wants to merge 1 commit into
AvaloniaUI:masterfrom
dimension-zero:master

Conversation

@dimension-zero

Copy link
Copy Markdown

Summary

  • DataGridCell, DataGridColumnHeader, and DataGridRowGroupHeader ControlTheme setters contained hardcoded values for FontSize, MinHeight, and Padding. Because ControlTheme applies at priority 11 (StyleTheme) and Application.Styles at priority 9, theme consumers could not override these values.
  • Extracted five dimension/padding values into named resource keys in Themes/Fluent.xaml: DataGridCellFontSize (15), DataGridCellMinHeight (32), DataGridColumnHeaderFontSize (12), DataGridColumnHeaderPadding (12,0,0,0), DataGridCellPadding (0).
  • DataGridRowGroupHeader and DataGridColumnHeader share DataGridCellMinHeight and DataGridCellFontSize where the logical sizes are the same.
  • No visual change when the keys are not overridden — all defaults are identical to the previous hardcoded literals.

Root cause

ControlTheme setters applied at priority 11 silently win over user-defined Application.Styles values at priority 9. A consumer writing:

<Application.Resources>
  <x:Double x:Key="DataGridCellFontSize">13</x:Double>
</Application.Resources>

would have had no effect before this change. Converting to {DynamicResource DataGridCellFontSize} defers the lookup to runtime and lets the resource chain find the consumer-supplied value first.

Test plan

  • dotnet build src/Avalonia.Controls.DataGrid — no XAML parse errors or missing-key warnings
  • Open the DataGrid sample and verify cell font size, column header font size, and row heights are visually identical to before
  • Override test: add <x:Double x:Key="DataGridCellFontSize">11</x:Double> to Application.Resources and confirm all three DataGrid control types change font size globally
  • Override test: add <x:Double x:Key="DataGridCellMinHeight">48</x:Double> and confirm DataGridCell, DataGridColumnHeader, and DataGridRowGroupHeader all grow to 48 px

Extract hardcoded FontSize, MinHeight, and Padding values from DataGridCell,
DataGridColumnHeader, and DataGridRowGroupHeader ControlThemes into named resource
keys in Themes/Fluent.xaml. ControlTheme setters apply at priority 11 (StyleTheme)
which silently overrides Application.Styles at priority 9; moving to DynamicResource
lets theme consumers override these values globally.

New keys: DataGridCellFontSize, DataGridCellMinHeight, DataGridColumnHeaderFontSize,
DataGridColumnHeaderPadding, DataGridCellPadding. No visual change when not overridden.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant