Xamarin Forms - Get position of item selected in Listview

后端 未结 2 912
慢半拍i
慢半拍i 2020-12-18 00:47

Im having a bit of trouble trying to get the position of an item in a ListView when its tapped.

Heres my code:

public MainPage()
{
    InitializeComp         


        
相关标签:
2条回答
  • 2020-12-18 01:35

    In SelectedItem event try this:

    var index = (myListView.ItemsSource as List<MyObject>).IndexOf (e.SelectedItem as MyObject);
    
    0 讨论(0)
  • 2020-12-18 01:44

    While adding items in listView , you can set styleId of that item . in ItemTapped body you will have access to that item thereby access to styleId of that item .

    0 讨论(0)
提交回复
热议问题