title: Xamarin.Forms ListView change Cell on ContextMenu open
body: <p>I use Xamarin.Forms to define a <code>ListView</code>. This <code>ListView</code> defines some <code>ContextAction</code>s on inside the <code>ViewCell</code>. Depending on the platform, these context actions are then presented to the user. In Android, this is triggered by long-pressing the specific item. Sadly, this Item will not be (properly) highlighted, as can be seen in this screenshot (I long-pressed <em>Third Item</em>, sadly I can't yet embed images).</p>
  
  <p><a href="https://i.stack.imgur.com/Ko9kG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ko9kG.png" alt="enter image description here"></a></p>
  
  <p><strong>Is there a way to modify the Cell when the context menu opens?</strong> Specifically asking for a solution for Android, but a general answer is welcome as well. The goal eventually is to improve highlighting, e.g. by changing the cell's background color. Modifying the cell, when one <code>ContextAction</code> is pressed, is not what I am looking for.</p>
  
  <p>I browsed through the source code of Xamarin.Forms and thought about somehow inheriting from e.g. the ViewCell class, but couldn't find an event or command that would be triggered / called upon long-pressing an item. I have set up a simple repository to which illustrates the behavior: <a href="https://github.com/maddin25/soq_listview_customCell" rel="nofollow noreferrer" title="GitHub repository">GitHub repository</a></p>
  
  <p><strong>The most important code snippets</strong></p>
  
  <ul>
  <li><p>ListView definition in XAML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ListViewContextMenu" x:Class="ListViewContextMenu.ListViewContextMenuPage"&gt;
      &lt;ListView x:Name="MyListView"&gt;
          &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;ViewCell&gt;
                      &lt;ViewCell.ContextActions&gt;
                          &lt;MenuItem Text="Action" Command="{Binding OnAction}" CommandParameter="{Binding .}"/&gt;
                      &lt;/ViewCell.ContextActions&gt;
                      &lt;Label Text="{Binding Name}" /&gt;
                  &lt;/ViewCell&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
  &lt;/ContentPage&gt;
  </code></pre></li>
  <li><p>MyItem definition (MVVM)</p>
  
  <pre><code>using System.Diagnostics;
  using Xamarin.Forms;
  
  namespace ListViewContextMenu
  {
      public class MyItem
      {
          public string Name { get; set; }
          public Command OnAction { get; set; }
  
          public MyItem()
          {
              OnAction = new Command((obj) =&gt; Debug.WriteLine($"Item {obj.ToString()} clicked"));
          }
      }
  }
  </code></pre></li>
  </ul>