42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media;
|
|
|
|
namespace JiangsuEarthquake.Common.ValueToBrushConvert
|
|
{
|
|
public class ValueToBrushConvertAttitude : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
double number = ConvertToDouble(value);
|
|
if (number > ConvertToDouble(parameter) || number < -20)
|
|
{
|
|
return new SolidColorBrush(Colors.Red); // 返回大于某个值的颜色
|
|
}
|
|
else
|
|
{
|
|
return new SolidColorBrush(Colors.White); // 返回默认颜色或背景色
|
|
}
|
|
}
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return new SolidColorBrush(Colors.Green); // 返回默认颜色或背景色
|
|
}
|
|
|
|
|
|
private double ConvertToDouble(object value)
|
|
{
|
|
double d;
|
|
double.TryParse(value.ToString(), out d);
|
|
return d;
|
|
}
|
|
}
|
|
}
|