IndexConverter .cs 869 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. namespace PDF_Office.DataConvert
  10. {
  11. public class IndexConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type TargetType, object parameter, CultureInfo culture)
  14. {
  15. ListViewItem item = (ListViewItem)value;
  16. ListView listView = ItemsControl.ItemsControlFromItemContainer(item) as ListView;
  17. int index = listView.ItemContainerGenerator.IndexFromContainer(item) + 1;
  18. return index.ToString();
  19. }
  20. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  21. {
  22. throw new NotImplementedException();
  23. }
  24. }
  25. }