I am using a DataGridTemplateColumn
to show a CheckBox in the Header. The Checkbox is used to show if alle cells are checked
and to (un-)check all cells.
XAML:
<DataGridTemplateColumn>
<DataGridTemplateColumn.Header>
<CheckBox IsChecked="{Binding Path=DataContext.AreAllVehiclesChecked, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl, AncestorLevel=1}}" Command="{Binding Path=DataContext.ChangeAllItemsSelectedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl,AncestorLevel=1}}" IsThreeState="False" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Command="{Binding Path=DataContext.ChangeItemSelectionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl,AncestorLevel=1}}" CommandParameter="{Binding }"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Error Message:
System.Windows.Data Error: 40 : BindingExpression path error: 'IsSearchSelected' property not found on 'object' ''CheckBox' (Name='')'. BindingExpression:Path=IsSearchSelected; DataItem='CheckBox' (Name=''); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1')
System.Windows.Data Error: 40 : BindingExpression path error: 'CreateProjectFromSelectedVehiclesDemandedCommand' property not found on 'object' ''CheckBox' (Name='')'. BindingExpression:Path=CreateProjectFromSelectedVehiclesDemandedCommand; DataItem='CheckBox' (Name=''); target element is 'CheckBox' (Name=''); target property is 'Command' (type 'ICommand')
What bugs me like hell is taht the DataTemplate with the CheckBox for all single cells is working just fine. The Property and the command are correctly bound. What doesn't work is the checkbox in the header. I have (the very same structure) correctly running in another project.
Any ideas what I am doing wrong?
UPDATE: I tried it again this morning (because of using snoop etc.) and suddenly - without changing code - it works (again). What's the best-StackOverflow-practice here -> Deleting the question?
Thanks again to everyone who was trying to help me!