using Gestor.Common.Helpers; using System; using System.Globalization; using System.Windows.Data; using System.Windows.Markup; using System.Windows.Media; namespace Gestor.Common.Converters { public class TarefaBackgroundColorConverter : MarkupExtension, IValueConverter { public TarefaBackgroundColorConverter() { } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && !((DateTime)value < Functions.GetNetworkTime())) { return new SolidColorBrush(Colors.Black); } return new SolidColorBrush(this.ConvertStringToColor("#fc636b")); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } public Color ConvertStringToColor(string hex) { hex = hex.Replace("#", ""); byte num = 255; byte num1 = 255; byte num2 = 255; byte num3 = 255; int num4 = 0; if (hex.Length == 8) { num = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber); num4 = 2; } num1 = byte.Parse(hex.Substring(num4, 2), NumberStyles.HexNumber); num2 = byte.Parse(hex.Substring(num4 + 2, 2), NumberStyles.HexNumber); num3 = byte.Parse(hex.Substring(num4 + 4, 2), NumberStyles.HexNumber); return Color.FromArgb(num, num1, num2, num3); } public override object ProvideValue(IServiceProvider serviceProvider) { return this; } } }