DataGrid有时需要对某个表格的数据进行突出显示:
思路:利用IMultiValueConverter对多参数的数据进行后台验证,返回值可针对字体、背景色、字体大小等可视数据。
前端代码如下:
后台转换器如下:
public class MultiParaToColorConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if ((values[1] != null) && (values[0] != null))
{
if (values[1].ToString() != values[0].ToString())
{
return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
}
else
{
return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent);
}
}
else
{
return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent);
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}