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). (aside: Seems Adding items works fine. Changing items doesnt propagate the update.)
The only workaround is to do somelistview.ItemsSource=null; somelistview.ItemsSource=originalSource;
after any remove(or edit) operations. Why does the native adapter not fire it's event??
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)
{
items.RemoveAt (0);
// following code will fix the issue - shouldnt be necessary.
//buggy.ItemsSource = null;
//buggy.ItemsSource = items;
}
}
<?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>
Exception:
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)]