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).

  1. A ResourceDictionary containing the lines for colors and themes of Material Design in XAML as given in the Super Quick Start.
  2. A XAML file that defines the DataGrid and also adds that ResourceDictionary to the Resources of its top-level FrameworkElement. ~3. The entry point of the application is a static Main method.~ ~4. That entry point instantiates the singleton Application and sets its Resources to those in the ResourceDictionary mentioned above.~
  3. Application sets its Resources to those in the ResourceDictionary mentioned above.

Code is available in this repo or in this ZIP.

Steps to reproduce

  1. Run the application in Visual Studio
  2. Open the Output window
  3. 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.

2020-12-19_15-47-15_435

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)

Most upvoted comments

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

  <Window.Resources>
    <ResourceDictionary Source="MyDictionary.xaml"/>
  </Window.Resources>

it works as expected!