0

我有以下数据网格,如果网格设置为只读但不知道如何设置条件,我想为 cover = false 的行着色。问题似乎与第一个条件有关,其中cover = false,好像我删除了这个条件另一个正在工作

        <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>
4

1 回答 1

2

我在上面注意到,当您将 Cover 绑定到复选框列时,您使用了转换器

Converter={StaticResource YNToBoolConverter}}

暗示 Cover 属性不是布尔值。您是否在条件绑定上尝试过相同的转换器?

于 2012-06-22T21:34:13.910 回答