1
0

TextToColorConverter.cs 880 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. using System.Windows.Media;
  5. namespace GeekDesk.Converts
  6. {
  7. internal class TextToColorConverter : IValueConverter
  8. {
  9. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  10. {
  11. if (value == null)
  12. {
  13. return null;
  14. }
  15. string str = value as string;
  16. return new SolidColorBrush((Color)ColorConverter.ConvertFromString(str));
  17. }
  18. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  19. {
  20. if (value == null)
  21. {
  22. return null;
  23. }
  24. string str = value as string;
  25. return new SolidColorBrush((Color)ColorConverter.ConvertFromString(str));
  26. }
  27. }
  28. }