C# My IconverterClass更改所有列的值
我有一个包含不同列的表,我在此代码中显示了两个列:C# My IconverterClass更改所有列的值,c#,wpf,binding,C#,Wpf,Binding,我有一个包含不同列的表,我在此代码中显示了两个列: <DataGridTextColumn Header="Allocated" Binding="{Binding Allocated}" > <DataGridTextColumn.ElementStyle> <Style TargetType="{x:Type TextBlock}"> <Setter Property="Background"> <
<DataGridTextColumn Header="Allocated" Binding="{Binding Allocated}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource converter}">
<Binding Path="Current_Phase" />
<Binding Path="Status" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Op10}" Header="WIP OP10" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource converter}">
<Binding Path="Current_Phase" />
<Binding Path="Status" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
请帮助PP,我不知道该怎么办。我不明白你的问题:
您的转换器返回绿色的“op10”和“op30”,您将该转换器绑定到两列,因此它将两列都更改为绿色。如果不想更改列op10,请删除与转换器的绑定。嗨,丹尼尔,我没有删除与转换器的绑定,因为我还希望在currentPhase为op10时更改列op10。基本上,我有两列op10和op30,我想根据当前阶段的valeu将颜色更改为列。这就是为什么我要把两者都捆绑起来。我不知道还有别的办法。你还有其他建议吗?!因此,如果currentPhase为op10,则希望列op10为绿色,并且仅在此时。如果当前相位为op30,您是否希望分配的列为绿色?是的,没错!!每个列需要不同的I转换器类吗?!或者向转换器添加第三个参数,并传递一个常量值。然后,这个常量值决定应该使用哪个if语句。非常感谢Daniel,我正在传递值做源代码
object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string type = values[0].ToString();
string status = values[1].ToString();
if (type == "op10" && status == "10")
{
return Brushes.Green;
}
else if ( type == "op30" && status == "30")
{
return Brushes.Green;
}
else
{
return DependencyProperty.UnsetValue;
}
}