2

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!

Community
  • 1
  • 1
basti
  • 2,649
  • 3
  • 31
  • 46
  • Solution already discussed in this.. http://stackoverflow.com/questions/7711275/bind-datagrid-column-visibility-mvvm/7711611#7711611 – WPF-it Jul 12 '12 at 09:41
  • That doesn't explain why it is working in the other project. – basti Jul 12 '12 at 10:12
  • Double-check your `RelativeSource` binding to be sure its finding the object containing the `DataContext` you want. I use [Snoop](http://snoopwpf.codeplex.com/) to debug things like this – Rachel Jul 12 '12 at 15:52
  • I will try out snoop an be reporting back, the strange thing is, that the CheckBox in the `` is working just fine. But not the CheckBox in the `` – basti Jul 13 '12 at 06:36

0 Answers0