title: Xamarin.Forms ListView Deletion of Items holds old values
body: <p>I have a ListView and populate it via DataBinding to a Lists Property in my ViewModel. Additionally, I have a menu for the ListView, with a Delete Command, also bound to my ViewModel.
  My Problem is now, if I have the ListView initialized, I can delete the lists in it. If I add new lists, I can delete all lists. But then, if I add new items, I can't delete them, because the List I get from the DeleteCommand is the old, already deleted list.</p>
  
  <p>So, after deleting lists, they seem to be somehow, somewhere still present and I can only delete new lists, if the total amount of current lists is higher, than any previous amount of deleted lists.</p>
  
  <p>I hope this is a somehow understandable explanation of my problem.</p>
  
  <p>The Binding is working and Lists Property in my ViewModel holds the correct values, but the "sender" ItemList in the DeleteListCommand is the old ItemList.</p>
  
  <p>Here is my XAML for my ListView:</p>
  
  <pre><code>&lt;ListView x:Name="listView" ItemsSource="{Binding Lists}" &gt;
      &lt;ListView.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;ViewCell x:Name="viewCell"&gt;
                  &lt;ViewCell.ContextActions&gt;
                      &lt;MenuItem Command="{Binding BindingContext.RenameListCommand, Source={x:Reference listView}}" CommandParameter="{Binding .}" Text="Rename" /&gt;
                      &lt;MenuItem Command="{Binding BindingContext.DeleteListCommand, Source={x:Reference listView}}" CommandParameter="{Binding .}" IsDestructive="True" Text="Delete" /&gt;
                  &lt;/ViewCell.ContextActions&gt;
                  &lt;ContentView Margin="0,2,0,2"
                                      HeightRequest="50"
                                      BackgroundColor="{Binding Color}"&gt;
  
                      &lt;ContentView.GestureRecognizers&gt;
                          &lt;TapGestureRecognizer BindingContext="{Binding Source={x:Reference listView}, Path=BindingContext}"
                                                          Command="{Binding ListTappedCommand}" 
                                                          CommandParameter="{Binding Source={x:Reference viewCell}, Path=BindingContext}" /&gt;
                      &lt;/ContentView.GestureRecognizers&gt;
                      &lt;ContentView.Content&gt;
  
                          &lt;Label Text="{Binding Name}"
                                      HorizontalTextAlignment="Center"
                                      VerticalTextAlignment="Center"
                                      TextColor="White" 
                                      IsEnabled="True"/&gt;
                      &lt;/ContentView.Content&gt;
  
                  &lt;/ContentView&gt;
              &lt;/ViewCell&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListView.ItemTemplate&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>And here is  my ViewModel:</p>
  
  <pre><code>...
  public ObservableCollection&lt;ItemList&gt; lists = new ObservableCollection&lt;ItemList&gt;();
          public ObservableCollection&lt;ItemList&gt; Lists
          {
              get { return lists; }
              set
              {
                  lists = value;
                  OnPropertyChanged("Lists");
              }
          }
  public event PropertyChangedEventHandler PropertyChanged;
  
  ...
  
  this.DeleteListCommand = new Command&lt;ItemList&gt;((sender) =&gt;
              {
                      OnDeleteList(sender);
              });
  
  ...
  
  public ICommand DeleteListCommand { get; set; }
  private void OnDeleteList(ItemList itemList)
          {
              Lists.Remove(itemList);
          }
  
  ...
  
  protected void OnPropertyChanged(string propertyName)
          {
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
          }
  </code></pre>