StringToColorConverter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Data;
  7. using System.Windows.Media;
  8. namespace Venus_Themes.Converters
  9. {
  10. public class StringToColorConverter : IValueConverter
  11. {
  12. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. if (value == null) return new SolidColorBrush(Colors.Red);
  15. switch (value.ToString())
  16. {
  17. case "Information":
  18. return new SolidColorBrush(Colors.Green);
  19. case "Warning":
  20. return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffd400"));
  21. case "Alarm":
  22. return new SolidColorBrush(Colors.Red);
  23. default:
  24. return new SolidColorBrush(Colors.Silver);
  25. }
  26. }
  27. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  28. {
  29. if (value == null)return false;
  30. if (!(value is bool))
  31. return false;
  32. return !(bool)value;
  33. }
  34. }
  35. }