I'm dealing with a large WPF application that is outputting a large number of binding errors. A typical error looks like this:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
Problem is I don't know where in the app this is coming from. Searching the entire solution for AncestorType={x:Type ItemsControl} doesn't necessary help since I still don't know which result is the culprit. I've tried setting PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.All;
but the extra information doesn't help locate the problematic bindings. File names and line numbers is really what I need. Is there anyway to get this information? The only other solution I can think of is to assign names to the canidates then narrow it down from there. In that vein, is there a way to automatically assign a unique x:Name to all namable elements throughout the solution?