Skip to content

Fluent Themes contain invalid DataGridColumn styles #9755

@MitchRazga

Description

@MitchRazga

Description

Iterating through the resources of any Fluent theme will throw this exception
ArgumentException: 'DataGridCheckBoxColumn' type must derive from FrameworkElement or FrameworkContentElement.

Which leads back to these styles:

<Style x:Key="DefaultDataGridCheckBoxColumnCellStyle" TargetType="{x:Type DataGridColumn}" />

<Style TargetType="{x:Type DataGridTextColumn}">
<Setter Property="EditingElementStyle" Value="{StaticResource TextBoxStyle}" />
</Style>

<Style TargetType="{x:Type DataGridCheckBoxColumn}">
<Setter Property="ElementStyle" Value="{StaticResource DataGridCheckBoxElementDefaultStyle}" />
<Setter Property="EditingElementStyle" Value="{StaticResource DataGridCheckBoxEditingElementDefaultStyle}" />
</Style>

This is because DataGridColumn and derived types inherit from DependencyObject not FrameworkElement or FrameworkContentElement and therefore cannot be styled.

Reproduction Steps

TestResources.zip

Expected behavior

Iterating through the framework's resources should not cause an exception.
DataGridColumn, DataGridTextColumn and DataGridCheckBoxColumn should not have any styles.

Actual behavior

ArgumentException: 'DataGridColumn' type must derive from FrameworkElement or FrameworkContentElement.
ArgumentException: 'DataGridTextColumn' type must derive from FrameworkElement or FrameworkContentElement.
ArgumentException: 'DataGridCheckBoxColumn' type must derive from FrameworkElement or FrameworkContentElement.

Regression?

No response

Known Workarounds

No response

Impact

Impacts all Fluent themes.

<Style x:Key="DefaultDataGridCheckBoxColumnCellStyle" TargetType="{x:Type DataGridColumn}" />

<Style x:Key="DefaultDataGridCheckBoxColumnCellStyle" TargetType="{x:Type DataGridColumn}" />

<Style x:Key="DefaultDataGridCheckBoxColumnCellStyle" TargetType="{x:Type DataGridColumn}" />

Configuration

.NET 9 Preview 7
Microsoft Windows 11 Pro 10.0.22631
x64

Other information

Looks this is also present in WPF UI too https://github.com/lepoco/wpfui/blob/4ac96867797267d566b82fbbfcab0c867353afaa/src/Wpf.Ui/Controls/DataGrid/DataGrid.xaml#L64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions