IsProgressedConverter.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.Controls;
  7. using System.Windows.Data;
  8. namespace PDF_Master.DataConvert
  9. {
  10. public class IsProgressedConverter : IMultiValueConverter
  11. {
  12. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. if ((values[0] is ContentControl && values[1] is int) == false)
  15. {
  16. return EnumCompare.None;
  17. }
  18. ContentControl contentControl = values[0] as ContentControl;
  19. int progress = (int)values[1];
  20. ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(contentControl);
  21. if (itemsControl == null)
  22. {
  23. return EnumCompare.None;
  24. }
  25. int index = itemsControl.ItemContainerGenerator.IndexFromContainer(contentControl);
  26. if (index < progress)
  27. {
  28. return EnumCompare.Less;
  29. }
  30. else if (index == progress)
  31. {
  32. return EnumCompare.Equal;
  33. }
  34. return EnumCompare.Large;
  35. }
  36. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  37. {
  38. throw new NotSupportedException();
  39. }
  40. }
  41. public enum EnumCompare
  42. {
  43. /// <summary>
  44. /// 小于
  45. /// </summary>
  46. Less,
  47. /// <summary>
  48. /// 等于
  49. /// </summary>
  50. Equal,
  51. /// <summary>
  52. /// 大于
  53. /// </summary>
  54. Large,
  55. None,
  56. }
  57. }