GroupHeaderConverter.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_Office.DataConvert
  9. {
  10. public class GroupHeaderConverter : IValueConverter
  11. {
  12. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  13. {
  14. if (value == null || string.IsNullOrEmpty(value.ToString())) return null;
  15. if (value.ToString().Length == 8)//日期
  16. {
  17. string dateStr = value.ToString();
  18. string text = dateStr.Substring(0, 4) + "-" + dateStr.Substring(4, 2) + "-" + dateStr.Substring(6, 2);
  19. return text;
  20. }
  21. else//页码
  22. {
  23. try
  24. {
  25. string page = "Page ";
  26. if ((int)value == -1)
  27. return null;
  28. else
  29. {
  30. return page + ((int)value + 1).ToString();
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. return null;
  36. }
  37. }
  38. }
  39. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  40. {
  41. throw new NotImplementedException();
  42. }
  43. }
  44. }