How can I pass 2 values to my ValueConverters Class?
I have got this on my Xaml , I am passing value allocated to change gridcell colour. But I want to check also at same time Entered variable value so I can change according to that.How can I pass 2 values so I can have conditions o开发者_运维技巧n my iconverter class.
<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:
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){
string input = value.ToString();
switch (input)
{
case "99":
return Brushes.Green;
case "96":
return Brushes.Green;
case "91":
default:
return DependencyProperty.UnsetValue;
}
}
Blockquote
Thanks in advance!
Use 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>
and ake your convet implement IMultiValueConverter
:
public class MyConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType,
object parameter, CultureInfo culture)
{...
精彩评论