StringToColorConverter.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. switch (value.ToString())
  15. {
  16. case "Information":
  17. return new SolidColorBrush(Colors.Green);
  18. case "Warning":
  19. return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffd400"));
  20. case "Alarm":
  21. return new SolidColorBrush(Colors.Red);
  22. default:
  23. return new SolidColorBrush(Colors.Silver);
  24. }
  25. }
  26. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  27. {
  28. if (!(value is bool))
  29. return false;
  30. return !(bool)value;
  31. }
  32. }
  33. }