Search code examples
wpfwpfdatagridmultidatatrigger

Multi trigger conditions not working on datagrid?


I have the following datagrid and I would like to color out the line where cover = false if the grid is set to read only but not sure how to set up the conditions. The problem seems to be with the first condition where cover = false as if i remove this condition the other one is working

        <DataGrid ItemsSource="{Binding AvailableRows}" AlternatingRowBackground="Lavender" Grid.Row="1"
                  IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertedBoolConverter}}" CanUserResizeColumns="True">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding TabName}" Header="Tab Name" CanUserSort="False" Width="1.5*">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding GroupSummaryTabRowDescription.Description}" Header="Benefit" CanUserSort="False" Width="2*" IsReadOnly="True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridCheckBoxColumn Binding="{Binding Cover, Converter={StaticResource YNToBoolConverter}}" Header="Cover" CanUserSort="False" Width="1*"/>
                <DataGridTextColumn Binding="{Binding RuleDescription, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="Rule" CanUserSort="False" Width="3.5*">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding AdditionalInfo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="Additional Info" CanUserSort="False" Width="4*">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
            </DataGrid.Columns>
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Cover}" Value="False"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=IsReadOnly}"  Value="True"/>
                            </MultiDataTrigger.Conditions>
                            <Setter  Property="Foreground" Value="Red" />
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
        </DataGrid>

Solution

  • I noticed above that when you bind Cover to a check box column, you use a converter

    Converter={StaticResource YNToBoolConverter}}
    

    suggesting that the Cover property is not a boolean value. Did you try the same converter on the condition binding?