Home > Software design >  ObserableCollection not triggering Change when Items are added/removed from list
ObserableCollection not triggering Change when Items are added/removed from list

Time:05-04

I have a problem with ReactiveUI ObservableCollection. I am trying to update the UI based on a list that changes in a ReactiveObject, but for some reason my list change is not triggered and I am not sure what I am doing wrong.

There is a full repo here : enter image description here

CodePudding user response:

randomService.WhenAnyValue(rs => rs.ModelList).WhereNotNull().Subscribe(_ => TriggerUpdateUI());

WhenAnyValue is just watching randomService for property change notifications for ModelList. You haven't set up anything to look for collection related changes.

From my point of view everything is correct if I read the definiton of ObservableCollection

"Represents a dynamic data collection that provides notifications when items get added or removed, or when the whole list is refreshed."

Your quote comes from the MS Docs on ObservableCollection. It is capable of producing collection change notifications, but you still need to setup something to react to them via ReactiveUI / DynamicData.

ReactiveUI Handbook - Collections

  • Related