我编写了一个转换器,并且能够根据行中的值设置单元格颜色。这是我的专栏:
<DataGridTextColumn Header="Name" Width="*" Binding="{Binding Path=Name}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="{Binding Path=Count, Converter={StaticResource CountToBrushConverter}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
它很好用,但是我必须为每一列添加这段代码。是否可以为所有列声明此DataGridTextColumn.ElementStyle
?
谢谢
答案 0 :(得分:0)
只需创建另一个针对Style
的隐式DataGridTextColumn
:
<Resources>
<Style TargetType="{x:Type DataGridTextColumn}">
<Setter Property="ElementStyle">
<Setter.Value>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="{Binding Path=Count, Converter={StaticResource CountToBrushConverter}}" />
</Style>
</Setter.Value>
</Seter>
</Style>
</Resources>