我的xaml中有一个数据网格:
<dg:DataGridTextColumn Header="A"
Width="110"
Binding="{Binding ValueA, StringFormat=N2}"
IsReadOnly="true"
FontWeight="Bold">
<dg:DataGridTextColumn.CellStyle>
<Style TargetType="dg:DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding ValueA, Converter={StaticResource MyConverterA}}"
Value="True">
<Setter Property="Background"
Value="LightYellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</dg:DataGridTextColumn.CellStyle>
</dg:DataGridTextColumn>
<dg:DataGridTextColumn Header="B"
Width="180"
Binding="{Binding B, StringFormat=N2}"
IsReadOnly="true"
FontWeight="Bold">
<dg:DataGridTextColumn.CellStyle>
<Style TargetType="dg:DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding MyVal, Converter={StaticResource MyConverterB}, **ConverterParameter=??**}"
Value="True">
<Setter Property="Background"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</dg:DataGridTextColumn.CellStyle>
</dg:DataGridTextColumn>
我需要传递Column&#34; A&#34;的值。作为MyConverterB的参数,使用ConverterParameter。 任何指针都很好吗?
感谢您的帮助。
答案 0 :(得分:4)
在这种情况下,您可以使用MultiBinding
代替ConverterParameter
。
<MultiBinding Converter="{StaticResource MyConverterB}">
<Binding Path="A" />
<Binding Path="B" />
</MultiBinding>
为此创建IMultiValueConverter
。
public class MyConverterB : IMultiValueConverter
{
public object Convert( object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
}
public object[] ConvertBack( object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture )
{
}
}
<强>更新强>
或者您可以尝试使用MultiDataTrigger
来更改颜色。也许有些转换器。条件与逻辑AND一样工作。
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=ValueA}" Value="True" />
<Condition Binding="{Binding Path=B}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Red" />
</MultiDataTrigger>