Boolean2StrConverter.cs 802 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. namespace HandyControl.Tools.Converter;
  5. public class Boolean2StringConverter : IValueConverter
  6. {
  7. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  8. {
  9. if (value is bool boolValue)
  10. {
  11. if (parameter is string str)
  12. {
  13. var arr = str.Split(';');
  14. if (arr.Length > 1)
  15. {
  16. return boolValue ? arr[1] : arr[0];
  17. }
  18. return "";
  19. }
  20. return "";
  21. }
  22. return "";
  23. }
  24. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  25. {
  26. throw new NotSupportedException();
  27. }
  28. }