MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

C# WPF DataGrid column header style error Cannot find source: RelativeSource FindAncestor

Open mojtabahakimian opened this issue 1 year ago • 1 comments

Bug explanation

I'm using C# WPF .NET Core 6 also Material Design Theme nuget, I have problem with DataGrid's Column Header Style I have Set a Style for Column Headers of my DataGrid When I'm trying to enter some data into my DataGrid suddenly I get this error in my XAML (Binding failures) :

HorizontalGridLinesBrush DataGridColumnHeader.BorderBrush Brush Cannot find source: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1'.

GridLinesVisibility DataGridColumnHeader.BorderThickness Thickness Cannot find source: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1'.

After a lot of Debugging I found out if I remove this BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}" from My Style <Style x:Key="CenteryHeaderstyle" TargetType="DataGridColumnHeader" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}"> It would be fixed !

https://stackoverflow.com/questions/77435140/c-sharp-wpf-datagrid-column-header-style-error-cannot-find-source-relativesourc

Version

4.9.0

mojtabahakimian avatar Nov 07 '23 02:11 mojtabahakimian

The problem is if I change this "DataGridColumnHeader" I will get "Error 1 null HorizontalGridLinesBrush DataGridColumnHeader.BorderBrush Brush Cannot find source: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1'."

"Error 1 null GridLinesVisibility DataGridColumnHeader.BorderThickness Thickness Cannot find source: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1'."

mojtabahakimian avatar Nov 07 '23 16:11 mojtabahakimian

Could you provide a test repository?

MichelMichels avatar Mar 31 '24 21:03 MichelMichels

This issue is marked stale because it has been open 30 days with no activity. Remove stale label or update the issue, otherwise it will be closed in 14 days.

github-actions[bot] avatar May 01 '24 01:05 github-actions[bot]

Closed due to staleness

MichelMichels avatar May 02 '24 21:05 MichelMichels