【发布时间】:2014-06-26 01:51:33
【问题描述】:
我有一个包含多个列的 DataGrid。其中一些列类似于
state|Color1|Color2|Color3|...
我想这样做:
If state==1 => RowForeground = Color1
If state==2 => RowForeground = Color2
If state==3 => RowForeground = Color3
...
我能想到的第一个解决方案是使用多个数据触发器:
<DataTrigger Binding="{Binding Path=state}" Value="0">
<Setter Property="Foreground" Value="{Binding Path=color0, Converter={StaticResource str2clrConverter}}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=state}" Value="1">
<Setter Property="Foreground" Value="{Binding Path=color1, Converter={StaticResource str2clrConverter}}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=state}" Value="2">
<Setter Property="Foreground" Value="{Binding Path=color2, Converter={StaticResource str2clrConverter}}"/>
</DataTrigger>
[...]
有没有更好的解决方案?
【问题讨论】:
标签: wpf xaml datagrid converter