Case
Say I have a Person
class, a PersonViewModel
and a PersonView
.
Updating properties from PersonView
to the Person
model is simple enough. PersonViewModel
contains a Person
object and has public properties the PersonView
binds to in order to update the Person model.
However.
Imagine the Person
model can get updated by Service
. Now the property change needs to be communicated to the PersonViewModel
and then to the PersonView
.
This is how I would fix it:
For each property on the Person
model I would raise the PropertyChanged event. PersonViewModel
subscribes to the PropertyChanged event of Person
. PersonViewModel
would then raise another PropertyChanged in order to update the PersonView
.
This to me seems the most obvious way but I kind of want to throw this question out there in the hope of someone showing me a nicer way. Is it really this simple or are there better ways to mark the model as modified and update the respective properties on the ViewModel?
Additions
The PersonView
's DataContext is PersonViewModel
. Person
gets populated from JSON and gets updated many times during its lifetime.
Feel free to suggest architectual changes for my particular case.
Answer
I marked aqwert as the answer of my question since it provided me with an alternative to the solution I already proposed.