Forum Xamarin Xamarin.Forms

BindableLayout get current element

Hikari91Hikari91 ITMember ✭✭✭
edited April 2019 in Xamarin.Forms

I have a StackLayout with BindableLayout.ItemsSource and BindableLayout.ItemTemplate.
I would like to add a GestureRecognizers with a Command and passing to it the Tapped element.

I have used this code but doesn't works:

    BindableLayout.ItemsSource="{Binding ListaTecnici}"
    BindableLayout.ItemTemplate="{Binding RigaTemplate}">
        <TapGestureRecognizer Command="{Binding TestCommand}" CommandParameter="{Binding .}"  />

If i set as CommandParameter {Binding .}, then whole ViewModel is passed at the command function.

What I can set like CommandParameter to pass the tapped item?

Thank you :smile:

Best Answer


  • Hikari91Hikari91 ITMember ✭✭✭
    edited April 2019

    @NickA said:

    I am just implementing the same thing right now. Check this out:

    He's using a FlexLayout, but will work for your StackLayout too.

    Thank you, I have tried your code but this error occurs when I run it:

    Unhandled Exception:
    System.InvalidCastException: Specified cast is not valid.

    Sorry, my mistake, but the OnItemTapped isn't trigger.

    I have found the problem.
    I created the DataTemplate with the container (a StackLayout) disabled >.<

    Now works fine!

    Thank you! :smiley:

Sign In or Register to comment.