user12945091
user12945091

Reputation:

Xamarin Binding ViewCell

<ListView Grid.Column="0" ItemsSource="{Binding CardItems[0]}" RowHeight="100">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout>
                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding CardItemTapCommand}" />
                                    </StackLayout.GestureRecognizers>
                                    <Image Source="{Binding Image}" HeightRequest="64"/>
                                    <Label Text="{Binding Text}"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

My view has its binding context set to the corresponding viewmodel. My CardItemTapCommand doesn't work.(i think this is happening because the binding context of each viewcell is the cardItem[0] list). Is setting the binding context of the cell to the viewmodel again a bad idea?

Upvotes: 0

Views: 101

Answers (1)

Ilnam Jeong
Ilnam Jeong

Reputation: 399

You can try this

<ContentPage ... 
             x:Name="PageName">

   <ContentPage.Content>
       ...
       <StackLayout.GestureRecognizers>
          <TapGestureRecognizer Command="{Binding Path=BindingContext.TapCommand, 
           Source={x:Reference PageName}}"/>
       </StackLayout.GestureRecognizers>
       ...
   </ContentPage.Content>
</ContentPage>

             

Upvotes: 1

Related Questions