Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

custom observablecollection don't work right with ListView

$
0
0

hi

i've created custom collection which implements INotifyCollectionChanged

here is sensible part


public event NotifyCollectionChangedEventHandler CollectionChanged;
public void Add(T item)
{
if (_innerCollection.Add(item))
{
if(CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); //i've checked, this code executes
}
}

i populate it, then i create ListView and add button code

var listView = new ListView {ItemsSource = myCollection};
....
button.Clicked += (sender, args) =>
{
myCollection.Add (new MyType{ Id = "3", Title = "Added" });
};

now, after i press the button, ListView becomes empty;

if i hook standart collection, all works well
private ObservableCollection myCollection = new ObservableCollection();

i see, that ListView only listens to CollectionChanged event and no other.

what's my problem? o_O

(everything is on one thread as far as i see. i don't create any other)


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>