mercredi 7 septembre 2016

WPF. Changing CheckBox IsChecked through MultiBinding doesn't triger CheckBox Command

I have Datagrid in my WPF app view where I use check boxes in row headers.

<DataGrid.RowHeaderTemplate>
<DataTemplate>
    <Grid >
        <CheckBox BorderThickness="0"  
                  Command="{Binding DataContext.AssignPartsToGroupCommand, RelativeSource={RelativeSource FindAncestor,
                                                                               AncestorType={x:Type UserControl}}}"                                          
                                    >
            <CheckBox.CommandParameter>
                <MultiBinding Converter="{StaticResource PartsGroupAssignConverter}">
                    <Binding Path="IsChecked" RelativeSource="{RelativeSource Self}" Mode="OneWay"/>
                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, 
                                                             AncestorType={x:Type DataGridRow}}" 
                             Path="DataContext" Mode="OneWay"/>
                </MultiBinding>
            </CheckBox.CommandParameter>
            <CheckBox.IsChecked>
                <MultiBinding  Converter="{StaticResource PartsGroupAssignedConverter}"  Mode="OneWay">
                    <Binding ElementName="partsGroupGrid" Path="SelectedItem.id"></Binding>
                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, 
                                                             AncestorType={x:Type DataGridRow}}" 
                             Path="DataContext" Mode="OneWay"/>
                    <Binding Path="IsSelected" Mode="OneWay"
                             RelativeSource="{RelativeSource FindAncestor,
                              AncestorType={x:Type DataGridRow}}"
                             />
                </MultiBinding>
            </CheckBox.IsChecked>
        </CheckBox>
    </Grid>
</DataTemplate>

As you can see I bind CheckBox property "IsSelected" to multiple values and one of them is DataGrid row selection:

   <Binding Path="IsSelected" 
            Mode="OneWay"
            RelativeSource="{RelativeSource FindAncestor,
                                  AncestorType={x:Type DataGridRow}}"
                                 />

My problem is - the command linked to CheckBox is not triggered when I check CheckBox by selecting row. But it triggers when I do it manually (with mouse). How can I solve this?

Aucun commentaire:

Enregistrer un commentaire