The normal way to do this is to use a value converter. Here's an example where I highlight negative numbers in red (typical in balance sheet type applications):
namespace MyNamespace
{
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
public class NegativeNumberColorConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var brush = new SolidColorBrush(Colors.Black);
if (value == null)
{
return brush;
}
decimal result;
var test = decimal.TryParse(value.ToString(), out result);
if (!test || result >= 0)
{
return brush;
}
return new SolidColorBrush(Colors.Red);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}