Forum Xamarin.Forms

Gesturerecognizer binding to command in complex layout

DinoNovak.3412DinoNovak.3412 USMember ✭✭
edited May 2020 in Xamarin.Forms
 I have a complex page layout:
               <StackLayout >
                        <ScrollView >
                            <FlexLayout BindableLayout.ItemsSource="">
                                                <components:SomeComponent />


Then there is component definition:

    <StackLayout xmlns=""
            xmlns:x=" x:Class="XXX.Components. SomeComponent">
            <TapGestureRecognizer Command="{Binding BindingContext.GoToDetailCommand}"
                                  CommandParameter="{Binding SomeID}"/>

In my case I am unable to fire Tap gesture. I suspect that FlexLayout BindableLayout.ItemsSource="{Binding XXX}" is binding to specific observable collection, so in component Binding BindingContext.GoToDetailCommand actually does not exist (they are defined in initial viewmodel for this page).
Can you please advise how to sort this issue?



  • LandLuLandLu Member, Xamarin Team Xamurai

    Firstly, name your component layout like:

    <StackLayout xmlns=""
                x:Class="XXX.Components. SomeComponent"

    And then change the binding like:

        <TapGestureRecognizer Command="{Binding Parent.BindingContext.GoToDetailCommand, Source={x:Reference ParentLayout}}"
                                CommandParameter="{Binding SomeID}"/>

    We could retrieve the parent FlexLayout that is located on the page through the parent property. Therefore, its binding context could also be accessed.

Sign In or Register to comment.