1

I have an ObservableCollection I'm attempting to bind to a ListView. I create everything just fine. The collection has multiple items in it (checked from both ends of the binding in ModelState and VisualState, but the View is never updated. I went ahead and bound directly to the ModelState's piece and everything worked just fine.

I suspect the cause is that INotifyCollectionChanged is not being sent through the binding. Is this something I can fix or is this a bug?

Timothy James
  • 1,062
  • 13
  • 25

1 Answers1

1

The binding between VisualState and ModelState are only done at the top level property. Hence if you replaced the ObservableCollection with a new ObservableCollection, that would be propagated. But the Binding doesn't know anything about the properties, hence it's not going to know about the INotifyCollectionChanged.

But, the binding should just copy the reference value from ModelState to VisualState, hence they should both reference the same object, therefore, adding a value at either end, should show a value change at the other end, and a raise of the event.

I would try manually attaching to the event, to confirm it is being raised.

Adam
  • 16,089
  • 6
  • 66
  • 109
  • What's the best way to do that? I tried `MyCollection.CollectionChanged += NewCollectionChangedEvent`, but that caused the page to not even load. Going back to the way I used to do it, other things in the UI are able to populate based on the items in the collection, the UI just doesn't populate the ListView. – Timothy James Jun 20 '17 at 22:51
  • @TimothyJames - I have gone through and tested this and it works as expected. If you have an ObservableCollection in the ModelState, with the same property in the VisualState, then bind that to a listview. I can then make updates to the observable in the ModelState and they are shown in the ListView (one exception, this doesn't work in UWP, I think its another XF bug). The only thing I can think of, is try initializing the Observable in the ModelState, in the constructor. Check out the Exrin repo and run sample. https://github.com/exrin/exrin – Adam Jun 27 '17 at 08:35
  • 1
    Got around to refactoring some stuff and could test this. My issue was (unsurprisingly) due to bad design. Working great now. Thanks, Adam! – Timothy James Aug 10 '17 at 23:51