views:

63

answers:

0

Hi,

I have a datagrid where the first column contains a checkbox to let the user selects specific rows. I have added a checkbox in the datagrid column header to check or uncheck all the rows.

Is it possible to add this functionality only with binding in XAML (no checked event).

<sdk:DataGrid AutoGenerateColumns="False" Grid.Row="1"  Name="grid" ItemsSource="{Binding myCollection, Mode=TwoWay}" >
        <sdk:DataGrid.Columns>
            <sdk:DataGridCheckBoxColumn Binding="{Binding myCollection.UserSelected, Mode=TwoWay}" >
                <sdk:DataGridCheckBoxColumn.HeaderStyle>
                    <Style TargetType="sdk:DataGridColumnHeader">
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <CheckBox x:Name="checkAll" IsThreeState="True"  
                                              IsChecked="{Binding myCollection.UserSelected, Mode=TwoWay, Converter={StaticResource threeStateConverter}}"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </sdk:DataGridCheckBoxColumn.HeaderStyle>
            </sdk:DataGridCheckBoxColumn>
            <sdk:DataGridTextColumn Binding="{Binding Description}" Header="Chemin" />
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>

I think there's something wrong with the "myCollection.UserSelected" part. ThreeStateConverter is a value converter that would return null when some items are selected, true when they are all selected, etc. but the Convert method is never called (even though the PropertyChanged event is raised when UserSelected is changed).

Any idea on how I can do it? Thank you.