IsProgressedConverter.cs 1.6 KB

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