BindableLayout get current element

Hikari91Hikari91 ITMember ✭✭
edited April 3 in Xamarin.Forms

Hi,
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:

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

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

Answers

  • Hikari91Hikari91 ITMember ✭✭
    edited April 4

    @NickA said:

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

    https://taubensee.net/adding-touch-events-to-flexlayouts/

    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.