Change a collection from a CollectionChanged event

I want to update the collection after changing it, but I cannot "get away" from this exception:

Cannot change ObservableCollection during CollectionChanged or PropertyChanged event.

Inside the event handler, I unsubscribe from the Collection event changed before changing anything to prevent endless loops, and after making the changes, I subscribe to the same event again.

private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    data.CollectionChanged -= CollectionChanged;
    data.Add("Item");
    data.CollectionChanged += CollectionChanged;
}

I tried using Dispatcher to call data.Add ("Item"), but no luck :(

+3
source share
1 answer

, , . , , , .

+1

Source: https://habr.com/ru/post/1754802/


All Articles