WPF: How do I debug binding errors?
- by Jonathan Allen
I'm getting this in my output Window:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ListBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
This is my XAML, which when run looks correct
<GroupBox Header="Grant/Deny Report">
<ListBox ItemsSource="{Binding Converter={StaticResource MethodBinder}, ConverterParameter=GrantDeny, Mode=OneWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Entity}"/>
<Label Content="{Binding HasPermission}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>