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()
{
InitializeComponent();
Results();
}
async void Results()
{
var service = new RestService();
response = await service.GetEventItemsAsync();
Debug.WriteLine("Found: " + response.Count + " events");
listView.ItemsSource = response;
listView.ItemTapped += async (sender, e) =>
{
// Get position of item tapped
};
}
Any help would be greatly appreciated.
SOLVED
Had to change ItemTapped to ItemSelected
Then inside the ItemSelected I just added in this line:
var i = (listView.ItemsSource as List<EventItems>).IndexOf(e.SelectedItem as EventItems);
In SelectedItem event try this:
var index = (myListView.ItemsSource as List<MyObject>).IndexOf (e.SelectedItem as MyObject);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With