ListViewIndexConverter.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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 System.Windows.Media;
  9. namespace FurnaceUI.Converter
  10. {
  11. /// <summary>
  12. /// ListView 控件 自增行序号
  13. /// </summary>
  14. public class ListViewIndexConverter : IValueConverter
  15. {
  16. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  17. {
  18. ListViewItem item = (ListViewItem)value;
  19. ListView listView = ItemsControl.ItemsControlFromItemContainer(item) as ListView;
  20. int index = listView.ItemContainerGenerator.IndexFromContainer(item) + 1;
  21. return index.ToString();
  22. }
  23. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  24. {
  25. throw new NotImplementedException();
  26. }
  27. }
  28. }