dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.04k stars 1.17k forks source link

Fluent Themes contain invalid DataGridColumn styles #9755

Open MitchRazga opened 1 week ago

MitchRazga commented 1 week ago

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: https://github.com/dotnet/wpf/blob/94751f56a45603960704642bdbc245a78e725644/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/DataGrid.xaml#L62 https://github.com/dotnet/wpf/blob/94751f56a45603960704642bdbc245a78e725644/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/DataGrid.xaml#L505-L507 https://github.com/dotnet/wpf/blob/94751f56a45603960704642bdbc245a78e725644/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/DataGrid.xaml#L792-L795

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. https://github.com/dotnet/wpf/blob/94751f56a45603960704642bdbc245a78e725644/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.HC.xaml#L1482 https://github.com/dotnet/wpf/blob/94751f56a45603960704642bdbc245a78e725644/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Dark.xaml#L1510 https://github.com/dotnet/wpf/blob/94751f56a45603960704642bdbc245a78e725644/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Light.xaml#L1505

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

miloush commented 1 week ago

I would suggest the issue is kept open until a PR merged.

MitchRazga commented 1 week ago

I would suggest the issue is kept open until a PR merged.

Whoops. Didn't realize that merging in the fork would close it here