public class BusNameColor : IMultiValueConverter
{
public object Convert ( object [ ] values, Type targetType, object parameter, CultureInfo culture)
{
DateTime plan = System. Convert. ToDateTime ( values[ 0 ] ) ;
DateTime start = System. Convert. ToDateTime ( values[ 1 ] ) ;
int time = ( start - plan) . Minutes;
SolidColorBrush bt;
if ( time <= 1 && time >= - 2 )
{
bt = new SolidColorBrush ( ( Color) ColorConverter. ConvertFromString ( "#313131" ) ) ;
}
else
{
bt = new SolidColorBrush ( ( Color) ColorConverter. ConvertFromString ( "#FF0000" ) ) ;
}
return bt;
}
public object [ ] ConvertBack ( object value , Type[ ] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException ( ) ;
}
}
< TextBlock x: Name= "BusName" FontSize= "{StaticResource smalFontSize}" Text= "{Binding nBusShowName}" HorizontalAlignment= "Center" VerticalAlignment= "Center" >
< TextBlock. Foreground>
< MultiBinding Converter= "{StaticResource BusNameColor}" >
< Binding Path= "sBusPlanTime" / >
< Binding Path= "nStartTime" / >
< / MultiBinding>
< / TextBlock. Foreground>
< / TextBlock>