I have a listbox with items bound to an ObservableCollection.
Now, from within the viewModel, I need to cause an update to the UI.
I dont have a refernce to the listbox from my view model.
If I remove or add an item from my ObservableCollection, the ui gets updated.
Based on some other logic I need to update the UI…but the ObservableCollection is the same.
How can I update the UI WITHOUT either adding or removing items from my ObservableCollection?
Thanks
If you need to change your UI because you’ve edited the items in your collection, then you should arrange for those items to implement the
INotifyPropertyChangedinterface. If the objects within your collection have aPropertyChangedevent, the UI will be listening for that event from individual items. (If possible, you could also change the items in your collection to beDependencyObjectswithDependencyProperties, which accomplishes the same goal.)If you really need to trigger a UI update when nothing at all about your collection has changed, the way to do it is to manually raise the
CollectionChangedevent. This can’t be done with theObservableCollection<>as is, but you could derive a new collection from that class, and call theprotected OnCollectionChangedmethod from within some new,publicmethod.