我有以下数据网格,如果网格设置为只读但不确定如何设置条件,我想为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>
答案 0 :(得分:2)
上面我注意到,当您将Cover绑定到复选框列时,您使用转换器
Converter={StaticResource YNToBoolConverter}}
建议Cover属性不是布尔值。您是否在条件绑定上尝试了相同的转换器?