我怎么能传递2个值给我的ValueConverters类

本文关键字:我的 ValueConverters 2个 怎么能 | 更新日期: 2023-09-27 17:49:35

我已经在我的Xaml上得到了这个,我正在传递分配给改变网格颜色的值。但我想同时检查输入的变量值,这样我就可以根据它来改变。我怎么能传递2个值,这样我就可以在我的转换器类上有条件。

<DataGridTextColumn Binding="{Binding Allocated}" Header="Allocated" >
                     <DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Background" Value="{Binding Allocated, Converter={StaticResource converter}}"/>
                            </Style>
                        </DataGridTextColumn.ElementStyle>     </DataGridTextColumn>

my Converter class:

IValueConverter

对象。转换(对象值,类型targetType,对象参数,System.Globalization.CultureInfo文化){

         string input = value.ToString(); 
         switch (input) 
         { 
             case "99":
                 return Brushes.Green;
             case "96":
                 return Brushes.Green;
             case "91":
              default:   
                 return DependencyProperty.UnsetValue; 
         }
    }

引用

提前感谢!

我怎么能传递2个值给我的ValueConverters类

使用MultiBinding:

<DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="Background">
            <Setter.Value>
                <MultiBinding Converter="{StaticResource converter}">
                    <Binding Path="Allocated" />
                    <Binding Path="Entered" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</DataGridTextColumn.ElementStyle>

,让你的convet实现IMultiValueConverter:

public class MyConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, 
                          object parameter, CultureInfo culture)
    {...