Search code examples
listviewxamarin.formsrow-number

How can a show row number from 1 to so on in a listview in xamarin forms?


I have got a requirement where I have to create a listView which adds item number with each item. I have got an idea of putting a number in model of item but I am unable to figure that out.


Solution

  • The easiest way should be to add one additional property Index to the ViewModel that is bound to the the ListView.ItemsSource and then simply represent it on the screen.

    Alternatively, if there is a need to use an enumerated ListView multiple times you could create a reusable control and move the logic from the ViewModel to the UI layer.

    So it all depends on your needs.