MalignantLevelToBrushConverter.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. using System.Windows.Markup;
  5. using System.Windows.Media;
  6. using AIPractice.Shared.Labels;
  7. namespace AIPractice.LabelEditor
  8. {
  9. [MarkupExtensionReturnType(typeof(IValueConverter))]
  10. public class MalignantLevelToBrushConverter : MarkupExtension, IValueConverter
  11. {
  12. public static MalignantLevelToBrushConverter Converter { get; private set; }
  13. static MalignantLevelToBrushConverter()
  14. {
  15. Converter = new MalignantLevelToBrushConverter();
  16. }
  17. public override object ProvideValue(IServiceProvider serviceProvider)
  18. {
  19. return Converter ?? (Converter = new MalignantLevelToBrushConverter());
  20. }
  21. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  22. {
  23. if (value != null)
  24. {
  25. var level = (MalignantLevel)value;
  26. switch (level)
  27. {
  28. case MalignantLevel.Low:
  29. return Brushes.Black;
  30. case MalignantLevel.Middle:
  31. return Brushes.DarkOrange;
  32. case MalignantLevel.High:
  33. return Brushes.Red;
  34. default:
  35. return Brushes.Black;
  36. }
  37. }
  38. return Brushes.Black;
  39. }
  40. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  41. {
  42. throw new NotImplementedException();
  43. }
  44. }
  45. }