GroupHeaderConverter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 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. {
  28. return null;
  29. }
  30. else
  31. {
  32. return page + ((int)value + 1).ToString();
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. return null;
  38. }
  39. }
  40. }
  41. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  42. {
  43. throw new NotImplementedException();
  44. }
  45. }
  46. }