Search code examples
c#xamarin.formscross-platformgesturebinding-context

Tap on a image inside the ListView, we should get a property value of specific Row


I have a listView, it contains an image with a list of items. When I tap on the image, I should get ProfileID of that row.

<Image Source="{Binding ImageUrl}" x:Name="{Binding ProfileID}" Aspect="AspectFill">
    <Image.GestureRecognizers>
    <TapGestureRecognizer Tapped="imageUserGesture_Tapped"/>
    </Image.GestureRecognizers>
</Image>

private async void imageUserGesture_Tapped(object sender, EventArgs e)
{
    CloseAnimation();
    var img = ((Image)sender);
    var name = img.Name;//How can I read name property ??????
    //var name = e.LoadFromXaml(MatchProfile).Name;
}


Solution

  • <Image Source="{Binding ImageUrl}"
           x:Name="imageUser"
           Aspect="AspectFill">
                                                                    
       <Image.GestureRecognizers>
          <TapGestureRecognizer Tapped="imageUserGesture_Tapped"
             Command="{Binding TapCommand}"
             CommandParameter="{Binding ProfileID}"
             NumberOfTapsRequired="1"/>
                                                                    
       </Image.GestureRecognizers>
    
    </Image>
    

    enter image description here