FirstCharacterConverter.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. namespace PDF_Master.DataConvert
  9. {
  10. public class FirstCharacterConverter : IValueConverter
  11. {
  12. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  13. {
  14. if (value == null)
  15. {
  16. return " ";
  17. }
  18. else
  19. {
  20. string firstCharacter=" ";
  21. string stringValue = value.ToString();
  22. if (!string.IsNullOrEmpty(stringValue) && value.ToString().Length >= 1)
  23. {
  24. firstCharacter = stringValue.Substring(0, 1);
  25. }
  26. return firstCharacter;
  27. }
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. throw new NotImplementedException();
  32. }
  33. }
  34. }