I hava a main view, where you have one object and you can change the properties of that object. But then I have a popup window when you click on a button: the advanced properties. But these changes that you do in the pop up window also have to be done in the object of the main view.
So I implemented a viewmodel as well for the popup. I can put here some code but this is quite useless, because I don’t have anything, just 2 viewmodels with bindings with some textboxes to change the properties of that object. So the 2 viewmodels don’t work together on the same object (this is what i should do i think).
It is just difficult for the popup to get to the object which you are working on in the mainview. In some way i should must be able to pass the changes which you made in the popup , to the main view (to the same object). Someone who knows how to do this? I am searching for this a long time, but i really don’t know to fix or to go around my problem 🙁 ..
There are several ways of achieving this, depending on your architecture. For example, if you are using a rich domain model, you may be binding directly to a Model property exposed on your view model. In which case, when you invoke the advanced property window, you can pass an instance of your existing model to that view model. Changes in the advanced property window will be bound to the same instance of your business object opened in the original window.
Alternatively, if you are using an anemic domain model where you don’t expose the model directly to the view, you can still pass the same instance of the model to the new window, but use a mediator pattern (or any other standard inter-view model communication techniques) to notify the original window when the advanced window closes. In this case, the advanced window would be the publisher, and the original window the subscriber.
When notified, the original window can invalidate all of its view model bindings so that the UI is updated as appropriate.