我有这个DataGrid,我一直在玩设置所选单元格的背景颜色:
<DataGridTextColumn Header="Next Study" Binding="{Binding NextStudy}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="25">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="ToolTip" Value="{Binding NextStudyDescription}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
它的工作原理如你所见:
但这不是我想要的。相反,我想突出显示值大于或等于18的所有单元格。所以我尝试了:
<DataGridTextColumn Header="Next Study" Binding="{Binding NextStudy}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{NextStudy Converter={StaticResource IsEqualOrGreaterThanConverter}, ConverterParameter=18}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="ToolTip" Value="{Binding NextStudyDescription}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
它不喜欢:<DataTrigger Binding="{NextStudy
此外,如果元素comboActiveStudentAssignmentType
选择索引为0,1或2,我想进行此背景测试。否则不需要执行此突出显示。
感谢。
答案 0 :(得分:1)
您遇到语法错误:Binding
是属性名称,您仍需将其声明为Binding
<DataTrigger Binding="{Binding NextStudy, Converter={StaticResource IsEqualOrGreaterThanConverter}, ConverterParameter=18}" Value="True">
至于问题的第二部分,您可以使用MultiDataTrigger
。对于触发器执行setter,MultiDataTrigger中的条件必须为ALL。您可能需要编写另一个转换器来将AssignmentType转换为True / False,您应该进行设置。
这是一个简单的例子:
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding NextStudy, Converter={StaticResource IsEqualOrGreaterThanConverter}, ConverterParameter=18}" Value="True"/>
<Condition Binding="{Binding comboActiveStudentAssignmentType, Converter={StaticResource YourOtherConverter}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Background" Value="Red"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>