I've spent quite some time to try and find an elegant solution for the following challenge. I've been unable to find a solution that's more than a hack around the problem.
I've got a simple setup of a View, ViewModel and a Model. I will keep it very simple for the sake of explanation.
- The
Modelhas a single property calledTitleof type String. - The
Modelis the DataContext for theView. - The
Viewhas aTextBlockthats databound toTitleon the Model. - The
ViewModelhas a method calledSave()that will save theModelto aServer - The
Servercan push changes made to theModel
So far so good. Now there are two adjustments I need to make in order to keep the Model in sync with a Server. The type of server is not important. Just know that I need to call Save() in order to push the Model to the Server.
Adjustment 1:
- The
Model.Titleproperty will need to callRaisePropertyChanged()in order to translate changes made to theModelby theServerto theView. This works nicely since theModelis the DataContext for theView
Not too bad.
Adjustment 2:
- Next step is to call
Save()to save changes made from theViewto theModelon theServer. This is where I get stuck. I can handle theModel.PropertyChangedevent on theViewModelthat calls Save() when the Model gets changed but this makes it echo changes made by the Server.
I'm looking for an elegant and logical solution and am willing to change my architecture if it makes sense.