using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace FilteringByCustomTypeSilverlight
{
    public class ValueFormatter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return string.Format("{0:C}", value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class ColorFormatter : IValueConverter
    {
        public Brush DefaultBrush { get; set; }
        public Brush HighlightBrush { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //OlapValue olapValue = value as OlapValue;

            //if ((double)olapValue.Value < 0)
            double valueAsDouble;
            if (double.TryParse(value.ToString(), NumberStyles.Currency, CultureInfo.CurrentCulture, out valueAsDouble) && valueAsDouble < 0)
            {
                return this.HighlightBrush;
            }

            return this.DefaultBrush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException("This Convert supports only OneWay binding");
        }
    }
}