Reputation: 4579
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
These errors appear in the immediate window in WPF. Why does this happen, and how can I stop it?
Upvotes: 3
Views: 3007
Reputation: 4579
This post here has details of workarounds for this issue. This one worked for me:
Add the following code to global styles:
<Style.Triggers>
<Trigger Property="HeadersVisibility" Value="Column">
<Setter Property="RowHeaderWidth" Value="0" />
</Trigger>
</Style.Triggers>
Upvotes: 2
Reputation: 473
Was having the same issue. I made a barebones WPF 4.7 app and in my case the SizeToContent attribute was causing it.
I had a StatusBar with its DataContext set to RelativeSource AncestorType=Window and a DataGrid was a sibling to it both within a DockPanel. The root Window had its SizeToContent set to Width.
When items were added to the DataGrid the binding errors you describe appeared. Without SizeToContent they don't. Using ElementName=rootWindow in the StatusBar instead of the Ancestor shenanigans also fixed it.
Upvotes: 1