How to get selected element of list in BindableLayout with TapGestureRecognizer

fsulserfsulser Member ✭✭
edited March 2019 in Xamarin.Forms

I have a page with multiple images in it. As the example is only a part of it I don't use a ListView, but instead a StackLayout with a BindableLayout.
To recognize taps on the rows I added a TapGestureRecognizer. How can I get which row/element from my list is selected?

In my xaml I created:

        <StackLayout BindableLayout.ItemsSource="{Binding ImageList}">
                    <StackLayout Orientation="Vertical">
                            <TapGestureRecognizer Command="{Binding RowTappedCommand}"/>

                        <Image Source="{Binding ImageURL}"/>
                        <Label Text="{Binding LabelText}"/>

In my ViewModel I have

    public class ImageListViewModel
        public ObservableCollection<Image> ImageList { get; set; }
        public ICommand RowTappedCommand { get; private set; }

        public ImageListViewModel()
            News = new ObservableCollection<News>();
            RowTappedCommand = new Command(RowTapped);

        void RowTapped()
            //get selected value;

I tried to use CommandParameter ="{Binding .}" but this will have the complete object and no indication on the row.


Sign In or Register to comment.