I have a model composed of three classes: A, B and C.
A has an ObservableCollection of B, B has an ObservableCollection of C.
C has a reference (not observable.. I don’t think is needed) to its parent (B), and B has a reference to A.
Each attribute of A, B and C notifies its changes.
I then have a Model class which “keeps track” of all the objects allocated. So it has an ObservableCollection of A, of B and of C (the only one that is required is for the As; I keep the lists for B and C only for faster reference).
My UI has a custom control: it has a ViewModel. The view has a list. Its ItemSources is bound to its ViewModel to an observablecollection named sensors. This ObservableCollection is of RowViewModel. Each RowViewModel keeps a reference to a C object.
My application loads the Model (creating A, B, C objects) and then sets the list of the view by calling this method (maybe this is the problem?)
public void setSensors(IList<C> list)
{
this.sensors.Clear();
if (list != null)
{
foreach (var row in list)
this.sensors.Add(new RowViewModel(row));
}
}
The problem is that if I modify a property of my C object, this is not reflected on the UI.
Someone can help me?
Thank you
Francesco
EDIT: (SOLVED)
thanks to your answers I checked my code and changed one thing: instead of binding my UI element to its ViewModel (and the viewModel simply “redirect” the call to the model property), I directly bind the UI to the real property, and it works!!
So… in MVVM I cannot use “shortcuts”??.. or if I use them I should register for notification of the property and “propagates” them?
I think your UI isn’t updated, because it’s binded to
RowViewModelobject, not toC. So, you should subscribe toPropertyChangedevent ofCin yourRowViewModel‘s constructor, and notify about those changes throughRowViewModel.PropertyChanged. By the way, can you provide an example of binding in your UI?UPDATED:
An example of “proxying”
PropertyChangedevent:You can read also http://george.softumus.com/2011/10/inotifypropertychanged-and-magic.html – how to avoid using “magic strings” (hardcoded constants) as property names.