This guide shows safe customization layers for TreeDataGrid theme behavior in XAML.
For most visual tweaks, override TreeDataGrid brush keys instead of replacing control templates.
<Application.Resources>
<SolidColorBrush x:Key="TreeDataGridGridLinesBrush" Color="#60FFB000"/>
<SolidColorBrush x:Key="TreeDataGridSelectedCellBackgroundBrush" Color="#66984AFB"/>
<SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPointerOverBrush" Color="#22007ACC"/>
</Application.Resources>
This is low-risk and survives future control-template changes better than full template replacement.
Use TreeDataGrid.Styles to apply local, scenario-specific styles:
<TreeDataGrid>
<TreeDataGrid.Styles>
<Style Selector="TreeDataGrid TreeDataGridRow:nth-child(2n)">
<Setter Property="Background" Value="#12808080"/>
</Style>
<Style Selector="TreeDataGrid TreeDataGridColumnHeader:nth-last-child(1)">
<Setter Property="TextBlock.FontWeight" Value="Bold"/>
</Style>
</TreeDataGrid.Styles>
</TreeDataGrid>
Advanced customization can replace ControlTheme entries from Generic.axaml (for example, expander chevron theme key TreeDataGridExpandCollapseChevron).
Prefer replacing one focused theme key rather than rewriting all TreeDataGrid control templates.
For deeper guidance:
Recommended setup:
Application.Styles.Application.Resources for global,
TreeDataGrid.Resources/TreeDataGrid.Styles for local behavior).Override works in Light but not Dark Cause: only one theme dictionary branch is overridden. Fix: define overrides for both variants or use variant-aware resources.
Custom selector does not apply Cause: selector does not match actual visual tree/control type. Fix: inspect runtime tree and adjust selector specificity.
Global override does not affect one grid Cause: grid-local resource/style definitions are shadowing app-level values. Fix: inspect nearest resource scope and remove or adjust local overrides.