ColorBrushConvert.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Data;
  8. using System.Windows.Media;
  9. namespace PDF_Master.DataConvert
  10. {
  11. /// <summary>
  12. /// Color to SolidColorBrush
  13. /// </summary>
  14. public class ColorBrushConvert : IValueConverter
  15. {
  16. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  17. {
  18. if((Color)value!=null)
  19. {
  20. return new SolidColorBrush((Color)value);
  21. }
  22. return Brushes.White;
  23. }
  24. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  25. {
  26. if((SolidColorBrush)value!=null)
  27. {
  28. return ((SolidColorBrush)value).Color;
  29. }
  30. return Brushes.White.Color;
  31. }
  32. }
  33. public class SizeBrushConvert : IValueConverter
  34. {
  35. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  36. {
  37. if (value == null)
  38. {
  39. return Brushes.Black;
  40. }
  41. else
  42. {
  43. if ((int)value>150)
  44. {
  45. return Brushes.Red;
  46. }
  47. else
  48. {
  49. return Brushes.Black;
  50. }
  51. }
  52. }
  53. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  54. {
  55. if ((SolidColorBrush)value != null)
  56. {
  57. return ((SolidColorBrush)value).Color;
  58. }
  59. return Brushes.White.Color;
  60. }
  61. }
  62. }