IsLastItemConverter.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 Venus_Themes.Converters
  9. {
  10. public class IsLastItemConverter : IMultiValueConverter
  11. {
  12. #region IValueConverter 成员
  13. public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  14. {
  15. if (value == null) return false;
  16. ContentControl contentPresenter = value[0] as ContentControl;
  17. ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(contentPresenter);
  18. bool flag = false;
  19. if (itemsControl != null)
  20. {
  21. int index = itemsControl.ItemContainerGenerator.IndexFromContainer(contentPresenter);
  22. flag = (index == (itemsControl.Items.Count - 1));
  23. }
  24. return flag;
  25. }
  26. public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
  27. {
  28. return null;
  29. }
  30. #endregion
  31. }
  32. }