Int2StrConverter.cs 933 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. namespace HandyControl.Tools.Converter;
  5. public class Int2StringConverter : IValueConverter
  6. {
  7. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  8. {
  9. if (value != null)
  10. {
  11. if (int.TryParse(value.ToString(), out var intValue))
  12. {
  13. if (parameter is string str)
  14. {
  15. var arr = str.Split(';');
  16. if (arr.Length > intValue)
  17. {
  18. return arr[intValue];
  19. }
  20. return intValue;
  21. }
  22. return intValue;
  23. }
  24. }
  25. return value;
  26. }
  27. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  28. {
  29. throw new NotSupportedException();
  30. }
  31. }