IsProgressedConverter.cs 1.6 KB

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