MaterialDesignInXamlToolkit: Broken binding errors after clicking on DataGrid header
Under a particular set of circumstances involving Material Design in XAML, clicking the header of a DataGrid causes WPF to log nine warnings to PresentationTraceSources.DataBindingSource.
As far as I can tell, each of the following is necessary (i.e. this is a minimal working reproduction).
- A
ResourceDictionarycontaining the lines for colors and themes of Material Design in XAML as given in the Super Quick Start. - A XAML file that defines the
DataGridand also adds thatResourceDictionaryto theResourcesof its top-levelFrameworkElement. ~3. The entry point of the application is astatic Mainmethod.~ ~4. That entry point instantiates the singletonApplicationand sets itsResourcesto those in theResourceDictionarymentioned above.~ Applicationsets itsResourcesto those in theResourceDictionarymentioned above.
Code is available in this repo or in this ZIP.
Steps to reproduce
- Run the application in Visual Studio
- Open the Output window
- Click the header of the
DataGrid
Expected behavior
Nothing appears in the Output window
Actual behavior
WPF logs nine binding errors to PresentationTraceSources.DataBindingSource, which show up in the Output window.

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGridRow', AncestorLevel='1''. BindingExpression:Path=Foreground; DataItem=null; target element is 'DataGridCell' (Name=''); target property is 'Foreground' (type 'Brush')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HorizontalGridLinesBrush; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'BorderBrush' (type 'Brush')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=GridLinesVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'BorderThickness' (type 'Thickness')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGridRow', AncestorLevel='1''. BindingExpression:Path=Foreground; DataItem=null; target element is 'DataGridCell' (Name=''); target property is 'Foreground' (type 'Brush')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HorizontalGridLinesBrush; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'BorderBrush' (type 'Brush')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=GridLinesVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'BorderThickness' (type 'Thickness')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGridRow', AncestorLevel='1''. BindingExpression:Path=Foreground; DataItem=null; target element is 'DataGridCell' (Name=''); target property is 'Foreground' (type 'Brush')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HorizontalGridLinesBrush; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'BorderBrush' (type 'Brush')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=GridLinesVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'BorderThickness' (type 'Thickness')
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 3
- Comments: 22 (20 by maintainers)
I figured out the cause of your issue on your repo 😃 You are merging “MyDictionary.xaml” both into your App.xaml and Window.xaml. Merging it into App.xaml is enough for the whole application, so if you just remove
it works as expected!