samedi 16 septembre 2017

WPF MVVM Master-Detail Data

I have a DataGrid that creates Checkboxes in a column using an ItemsControl. The ItemSource is of type List<CheckboxClass> where the CheckboxClass contains a bool IsCheckedProperty and an enum CboxType (used for the Checkbox content property.)

<DataGrid Margin="10" Name="dgItems"  AutoGenerateColumns="False" Grid.Column="0" ItemsSource="{Binding Path=RowItems}">
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ItemsControl ItemsSource="{Binding Path=Checkboxes}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Path=IsCheckedProperty}" Content="{Binding Path=CboxType}"></CheckBox>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid> 

Separately from the DataGrid, I have a checkbox where I want the IsChecked property to ultimately bind to the IsChecked property of the Checkbox in the SelectedItem of the DataGrid.

<CheckBox Content="Detail CheckboxType A">
    <CheckBox.IsChecked>
        <MultiBinding Converter="{StaticResource IsCheckedConverter}">
            <Binding ElementName="dgItems" Path="SelectedItem"></Binding>
            <Binding Path="RowItems/Checkboxes/CboxType"></Binding>
            <Binding Path="RowItems/Checkboxes/IsCheckedProperty"></Binding>
        </MultiBinding>
    </CheckBox.IsChecked>
</CheckBox>

The IsCheckedConverter is triggered when the SelectedItem of the DataGrid changes, but it does not trigger when a checkbox in the DataGrid is checked.

What needs to change in order to have this separate Checkbox trigger the IsCheckedConverter when a Checkbox in the DataGrid is checked?

Aucun commentaire:

Enregistrer un commentaire