using System; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Markup; using System.Windows.Media; namespace Gestor.Common.Converters { public class ComissaoColorConverter : MarkupExtension, IValueConverter { public ComissaoColorConverter() { } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return new SolidColorBrush(Colors.Red); } if ((int)Math.Round(double.Parse(value.ToString())) >= 0 && (int)Math.Round(double.Parse(value.ToString())) != 0) { return new SolidColorBrush(Colors.Red); } return new SolidColorBrush((Color)Application.Current.Resources["AggerBlue"]); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return (value == null || string.IsNullOrEmpty(value.ToString()) ? 0 : int.Parse(value.ToString())); } public override object ProvideValue(IServiceProvider serviceProvider) { return this; } } }