title: ViewModel Command call from ListView.ItemTemplate in Xamarin.Forms
body: <p>Here I am using MVVM architecture for developing applications. I have an image inside the listview and the listview binding with a list (ViewAcceptedList). Here I am using TapGestureRecognizer for the image. Inside the image I need to call a command (ChatTappedCommand). I am sharing my code, how I tried to achieve the requirement. I need help from an experienced one.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
      &lt;ContentPage xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;
                   xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
                   xmlns:d=&quot;http://xamarin.com/schemas/2014/forms/design&quot;
                   xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
                   xmlns:IC=&quot;clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin&quot; 
                   xmlns:Custom=&quot;clr-namespace:MTR.Customization&quot; xmlns:pv=&quot;clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView&quot; xmlns:local=&quot;clr-namespace:MTR.Views&quot;
                   mc:Ignorable=&quot;d&quot;
                   x:Class=&quot;MTR.Views.MailBox.MailBoxPage&quot;
                   xmlns:behaviors=&quot;clr-namespace:MTR.ViewModels.Behavior&quot; xmlns:VM=&quot;clr-namespace:MTR.ViewModels&quot;
                   BackgroundColor=&quot;#F8F0F0&quot;&gt;
      
          &lt;ContentPage.BindingContext&gt;
              &lt;VM:MailBoxPageViewModel/&gt;
          &lt;/ContentPage.BindingContext&gt;
          
          &lt;ContentPage.Content&gt;
      
                  &lt;ListView x:Name=&quot;MailboxAcceptedList&quot; 
                          IsVisible=&quot;{Binding ViewAcceptedList}&quot;
                          ItemsSource=&quot;{Binding MailedBoxAcceptedList}&quot;
                          SeparatorColor=&quot;Transparent&quot; 
                          VerticalScrollBarVisibility=&quot;Never&quot;
                          HasUnevenRows=&quot;True&quot;
                          RelativeLayout.YConstraint=&quot;{ConstraintExpression Type=RelativeToView, ElementName=stackNavigationBar, Property=Height,Constant=2, Factor=2.9}&quot;
                          RelativeLayout.HeightConstraint=&quot;{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=.8}&quot;
                          RelativeLayout.WidthConstraint=&quot;{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}&quot;&gt;
                              
                  &lt;ListView.Behaviors&gt;
                      &lt;behaviors:MailBoxListViewBehavior /&gt;
                  &lt;/ListView.Behaviors&gt;
      
                  &lt;ListView.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;ViewCell&gt;
      
                              &lt;Image  x:Name=&quot;imgChat&quot;
                                  Source=&quot;chat_32px.png&quot;
                                  HeightRequest=&quot;30&quot;
                                  WidthRequest=&quot;30&quot;&gt;
                                  &lt;Image.GestureRecognizers&gt;
                                      &lt;TapGestureRecognizer BindingContext=&quot;{Binding Source={x:Reference MailBoxPage}}&quot; Command=&quot;{Binding ChatTappedCommand}&quot;
                                                                                  CommandParameter=&quot;{Binding MTRID}&quot; /&gt;
                                      &lt;!--Command=&quot;{Binding Source={x:Reference Name=nameYourPage}, Path=BindingContext. EditarEnderecoCommand}&quot; CommandParameter=&quot;{Binding CliEndCep}&quot;
                                                          Command=&quot;{Binding ChatTappedCommand}&quot;
                                                          CommandParameter=&quot;{Binding Source={x:Reference Item}, Path=BindingContext}&quot;--&gt;
                                  &lt;/Image.GestureRecognizers&gt;
                              &lt;/Image&gt;
                                          
                          &lt;/ViewCell&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
              &lt;/ListView&gt;`enter code here`
      
  &lt;/ContentPage.Content&gt;
  
  
  //ViewModel:
  
  
  using MTR.Models.Interface;
  using MTR.Views;
  using System;
  using System.Collections.Generic;
  using System.Collections.ObjectModel;
  using System.Linq;
  using System.Text;
  using System.Windows.Input;
  using Xamarin.Forms;
  
  namespace MTR.ViewModels
  {
      public class MailBoxPageViewModel : BindableObject
      {
          private ObservableCollection&lt;MTR.Models.DbModel.Mail&gt; mailedAcceptedList;
          public ObservableCollection&lt;MTR.Models.DbModel.Mail&gt; MailedBoxAcceptedList
          {
              get =&gt; mailedAcceptedList;
              set
              {
                  if (value == mailedAcceptedList)
                      return;
  
                  mailedAcceptedList = value;
                  OnPropertyChanged();
              }
          }
         
          public ICommand ChatTappedCommand
          {
              get;
              private set;
          }
          private void ChatTapped(object obj)
          {
  
          }
  
          public MailBoxPageViewModel()
          {
              ChatTappedCommand = new Command(ChatTapped);
  
              MailedBoxAcceptedList = new ObservableCollection&lt;Models.DbModel.Mail&gt;();
          }
          
      }
  }
  </code></pre>
  <p>Here I am trying to call a Command inside the ViewModel class and also I need to send an Id with this call. (Command, CommandParameter, BindingContext)</p>