StringShowNameConvert.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Data;
  7. namespace FurnaceUI.Converter
  8. {
  9. public class StringShowNameConvert : IValueConverter
  10. {
  11. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  12. {
  13. if (value == null) return value;
  14. string s = value.ToString();
  15. int leng;
  16. if (s.Contains("\\"))
  17. {
  18. var temp = s.Split('\\');
  19. s = temp[temp.Length - 1];
  20. }
  21. if (int.TryParse(parameter.ToString(), out leng))
  22. {
  23. if (s.Length <= leng)
  24. return s;
  25. else
  26. return s.Substring(0, leng) + "...";
  27. }
  28. else
  29. return string.Empty;
  30. }
  31. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. }
  36. }