The code is below, I'm testing with android platform. When the item is removed, it remains in the listview, and when you interact with it the listview complains that the adapter state changed without a notification (IllegalStateException), see below also. The button click event handler runs on the UI thread, but I marshalled it anyway incase anybody says anything .
The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(-1, class android.widget.ListView) with Adapter(class md5d4dd78677dce656d5db26c85a3743ef3.ListViewAdapter)]
public class myvm
{
public String txt { get ; set; }
}
public partial class BuggyListView : ContentPage
{
BindingList<myvm> _items = new BindingList<myvm>();
public BindingList<myvm> items { get { return _items; } set{ items = value; } }
public BuggyListView ()
{
items.Add (new myvm () { txt = "daveeeeeeeeee" });
InitializeComponent ();
BindingContext = this;
}
void Rfirst(object s, EventArgs e)
{
Device.BeginInvokeOnMainThread (() => {
items.RemoveAt (0);
//buggy = null; // tried this..nothing..
//buggy.ItemsSource = items; // and this...also nothing...
});
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BuggyTestApp.BuggyListView">
<StackLayout Orientation="Vertical">
<ListView ItemsSource="{Binding items}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label HorizontalOptions="FillAndExpand" Text="{Binding txt}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Text="removefirst" Clicked="Rfirst"/>
</StackLayout>
</ContentPage>