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 PDF_Master.DataConvert
  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. ContentControl contentPresenter = value[0] as ContentControl;
  16. ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(contentPresenter);
  17. bool flag = false;
  18. if (itemsControl != null)
  19. {
  20. int index = itemsControl.ItemContainerGenerator.IndexFromContainer(contentPresenter);
  21. flag = (index == (itemsControl.Items.Count - 1));
  22. }
  23. return flag;
  24. }
  25. public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
  26. {
  27. return null;
  28. }
  29. #endregion IValueConverter 成员
  30. }
  31. }