Forum Xamarin.Forms

get the index of an element inside flowlistview

I am trying to get the index of tapped element which is a Label inside FlowListView. I can attach FlowItemTapped to the FlowListView and get the whole object, but in my case it's not the FlowItem that I want to render, but it's child. I attach Tapped to the child element and I can perform some alerts upon tapping that element, but I can't figure out how to get its index. And I need this in code behind directly. I read a few answers to similar questions but none of them seemed to be applicable for my case

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    You could get the index using the following code

    private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
        {
            View view = sender as View;
            var obj = view.BindingContext as Model;
    
            int index = viewmodel.list.IndexOf(obj); /
        }
    
Sign In or Register to comment.