How to display row numbers in a ListView?

前端 未结 10 889
盖世英雄少女心
盖世英雄少女心 2020-11-27 04:33

The obvious solution would be to have a row number property on a ModelView element, but the drawback is that you have to re-generate those when you add records or change sor

10条回答
  •  难免孤独
    2020-11-27 05:34

    This will work like a charm, I don't know about performance, Still we can give it a try

    Create a Multi Value Converter

    public class NumberingConvertor : IMultiValueConverter
     {
      public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
       if (values != null && values.Any() && values[0] != null && values[1] != null)
       {
        //return (char)(((List)values[1]).IndexOf(values[0]) + 97);
        return ((List)values[1]).IndexOf(values[0]) + 1;
       }
       return "0";
      }
    
      public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
      {
       return null;
      }
     }
    }
    
    
    

    and your Xaml like this

    
            
                
                    
                
            
            
                
                    
                        
                        
                    
                
            
        
    

    Idea is to send Object and list both to the converter and let converter decide the number. You can modify converter to display ordered list.

    提交回复
    热议问题