2
votes

I want label click Command binding inside a ListView, In ListView, I have a label. When click that label go to another page.

I tried this, but not working fine. Any other solution?

<Label Text="Message"  FontSize="12" Grid.Column="3"  HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand">
    <Label.GestureRecognizers>
        <TapGestureRecognizer BindingContext="{Binding Source={x:Reference newsfeedlist}, Path=BindingContext}"  Command="{Binding MessageCommand}" CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"/>
    </Label.GestureRecognizers>
</Label>
1

1 Answers

0
votes

A List view has its own bindingContext so the best is to referance the page then the command e.g.

  1. First Give your page a name

     <ContentPage 
         ....
         x:Name="FooPage" 
         Title="Foo">
    
  2. Then in your list

             <ListView x:Name="EmployeeListData"  ItemsSource="{Binding EmployeeList}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Padding="5"><Label Text="Click Me">
                                    <Label.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding Path=BindingContext.EmployeeActions, Source={x:Reference FooPage}}" CommandParameter="{Binding .}"></TapGestureRecognizer>
                                    </Label.GestureRecognizers> </Label>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
    
  3. Here is the secret source

    Command="{Binding Path=BindingContext.EmployeeActions, Source={x:Reference FooPage}}"