Passing variable from view to another view

Jan 9, 2011 at 1:36 PM

I would like know that is possible this scenario. I have active, view 1  I deactive this view and active view 2. During thic action I want pass variable from view model 1  to view model 2.  It is possible ?

Coordinator
Jan 9, 2011 at 3:59 PM

Yes. Search the forums. There have been several discussions on this.

Jan 9, 2011 at 4:00 PM

You may want to use the parent Conductor of the two VMs as a "coordinator", so that it could read some value esposed by a property in VM1 and push that value into VM2 at the right time.

Another option is using the parent Conductor as a bare "data holder" while the active role in passing data is kept by child VMs.
VM1 and VM2 can use their own lifecycle overrides (OnDeactivate and OnActivate, respectively) to set and read the value from it parent Conductor, reachable through the Screen.Parent property.

A third option, useful in more complex scenario and when you absolutely need to reduce coupling between classes, is to use the EventAggregator in VM1 to publish an app-wide event (with a payload containing the value to pass), to which the VM2 can appropriately react.