BoolToBrushConverter.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Aitex.Core.RT.Log;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Data;
  10. using System.Windows.Media;
  11. namespace MECF.Framework.UI.Core.Converters
  12. {
  13. public class BoolToBrushConverter : IValueConverter
  14. {
  15. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. try
  18. {
  19. bool isOpen = (bool)value;
  20. if (isOpen)
  21. {
  22. return System.Windows.Media.Brushes.White;
  23. }
  24. else
  25. {
  26. return System.Windows.Media.Brushes.Black;
  27. }
  28. }
  29. catch (Exception ex)
  30. {
  31. LOG.Write(ex);
  32. }
  33. return System.Windows.Media.Brushes.Black;
  34. }
  35. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  36. {
  37. try
  38. {
  39. System.Windows.Media.Brush brush = (SolidColorBrush)value;
  40. System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(brush.ToString());
  41. return color;
  42. }
  43. catch (Exception ex)
  44. {
  45. LOG.Write(ex);
  46. }
  47. return Colors.Black;
  48. }
  49. }
  50. }