title: Detecting tap on label, inside ViewCell, inside ListView
body: <p>I'm trying to handle something similar (from UI perspective), to:
  <a href="https://i.stack.imgur.com/j889e.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/j889e.jpg" alt="enter image description here"></a></p>
  
  <p>in order to invoke two different business logics for:</p>
  
  <ul>
  <li>tapping at ViewCell element itself (inside ListView) - in example navigate to different page</li>
  <li>tapping at Label element (<strong>Clickable Label</strong>), which is inside given ViewCell element - in example delete given object or smth else</li>
  </ul>
  
  <p>I would like to have whole "tapping" logic inside page <strong>ViewModel</strong>.</p>
  
  <p>Based on Xamarin forum proposes, I'm able to invoke some logic of "tapping" my <strong>delete</strong> action from cell, however directly inside my data model - which in my PoV is not good solution, as I would like to manipulate my List collection (so the most preferable way, would be to have this logic at page <strong>ViewModel</strong>).</p>
  
  <p>What I have right now:</p>
  
  <p>My page <strong>View XAML</strong> code looks like:</p>
  
  <pre><code>&lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App.Views.TestView"&gt;
    &lt;ContentPage.Content&gt;
      &lt;StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"&gt;
          &lt;ListView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" ItemsSource="{Binding MyItemsCollection}" SelectedItem="{Binding SelectedItem}"&gt;
            &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                &lt;ViewCell&gt;
                  &lt;StackLayout Orientation="Horizontal"&gt;
  
                    &lt;!-- Name Label --&gt;
                    &lt;Label Text="{Binding Name}" VerticalOptions="CenterAndExpand" HorizontalOptions="StartAndExpand" /&gt;
  
                    &lt;!-- Delete "Icon" --&gt;
                    &lt;Label Text="Clickable Label" VerticalOptions="CenterAndExpand" HorizontalOptions="EndAndExpand"&gt;
                      &lt;Label.GestureRecognizers&gt;
                        &lt;TapGestureRecognizer Command="{Binding OnClickableLabel}" CommandParameter="{Binding .}" /&gt;
                      &lt;/Label.GestureRecognizers&gt;
                    &lt;/Label&gt;
  
                  &lt;/StackLayout&gt;
                &lt;/ViewCell&gt;
              &lt;/DataTemplate&gt;
            &lt;/ListView.ItemTemplate&gt;
          &lt;/ListView&gt;
      &lt;/StackLayout&gt;
    &lt;/ContentPage.Content&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>My page <strong>View C#</strong> code looks like (not specific code there, except binding **BindingContext* to page ViewModel):</p>
  
  <pre><code>public partial class TestView : ContentPage
  {
      public TestView()
      {
          InitializeComponent();
          BindingContext = ServiceLocator.Current.GetInstance&lt;TestViewModel&gt;();
      }
  }
  </code></pre>
  
  <p>My page <strong>ViewModel C#</strong> code looks like:</p>
  
  <pre><code>public class TestViewModel : ViewModelBase
  {
      public TestViewModel()
      {
          MyItemsCollection = GetMyItemsCollection();
      }
  
      private List&lt;MyItem&gt; GetMyItemsCollection()
      {
          return new List&lt;MyItem&gt;
          {
              new MyItem
              {
                  ID = 1L,
                  Name = "Item 1 Name"
              },
              new MyItem
              {
                  ID = 2L,
                  Name = "Item 2 Name"
              },
              new MyItem
              {
                  ID = 3L,
                  Name = "Item 3 Name"
              }
          };
      }
  
      private List&lt;MyItem&gt; _myItemsCollection { get; set; }
  
      public List&lt;MyItem&gt; MyItemsCollection
      {
          get
          {
              return _myItemsCollection;
          }
          set
          {
              _myItemsCollection = value;
              RaisePropertyChanged();
          }
      }
  
      private MyItem _SelectedItem { get; set; }
  
      public MyItem SelectedItem
      {
          get
          {
              return _SelectedItem;
          }
          set
          {
              if (_SelectedItem != value)
              {
                  _SelectedItem = value;
                  RaisePropertyChanged();
  
                  Debug.WriteLine("SelectedItem: " + _SelectedItem.Name);
              }
          }
      }
  
      private RelayCommand&lt;object&gt; _OnClickableLabel;
  
      public RelayCommand&lt;object&gt; OnClickableLabel
      {
          get { return _OnClickableLabel ?? (_OnClickableLabel = new RelayCommand&lt;object&gt;((currentObject) =&gt; Test(currentObject))); }
      }
  
      private void Test(object currentObject)
      {
          Debug.WriteLine("This should work... but it's not working :(");
      }
  }
  </code></pre>
  
  <p>My <strong>data model</strong> code looks like:</p>
  
  <pre><code>public class MyItem
  {
      public long ID { get; set; }
      public string Name { get; set; }
  
      private RelayCommand&lt;object&gt; _OnClickableLabel;
  
      public RelayCommand&lt;object&gt; OnClickableLabel
      {
          get { return _OnClickableLabel ?? (_OnClickableLabel = new RelayCommand&lt;object&gt;((currentObject) =&gt; Test(currentObject))); }
      }
  
      private void Test(object currentObject)
      {
          Debug.WriteLine("This works... but it's not good idea, to have it here...");
      }
  }
  </code></pre>
  
  <p>Any idea what needs to be changed, in order to invoke <strong>OnClickableLabel</strong> directly inside my page <strong>ViewModel</strong> ?
  I know, that it's something wrong at:</p>
  
  <pre><code>&lt;TapGestureRecognizer Command="{Binding OnClickableLabel}" CommandParameter="{Binding .}" /&gt;
  </code></pre>
  
  <p>but don't know what :/.</p>
  
  <p>Help! Thanks a lot.</p>