MVVM SubViews

Jan 5, 2011 at 8:53 PM

Hi,

i want to open a subview (with viewmodel) from a (main) viewmodel.

my questions:

should i declare the subview like a normal view (e.g. DefineNavigationContent, MapViewModel...)?

to open the subview should i then "navigate" to the subview url?

how do i set presets in the subview from the main viewmodel? (via url? via message channels?)

how do i get back settings from the subview in the main viewmodel?

what is the best practise to handle this scenario?

a small code example would be very nice.... thanks!

Helmut

 

Coordinator
Jan 14, 2011 at 10:11 AM

Hi Helmut, sorry this question escaped me for a while. Now, how you declare depends on what you want to do - there two options basically, one let the sub-view have its own VM or two, let the sub-view share its parent's VM. Infact, I've discussed this before here http://nroute.codeplex.com/Thread/View.aspx?ThreadId=225598 - you'll also find some sample code there and in the repository too (see the Wizard sample). 

As for setting up the views, you can basically put in a container and specify the Url, or alternatively, you can use something like a navigation-adapter to turn a content-control or panel into a container (see http://groups.google.com/group/nroute/browse_thread/thread/81ef05b4efc5776d). And in either case, you can also use the NavigateAction to navigate into your sub-view container, this will allow you to pass in parameters.

The specifics of getting data back from the sub-view depends on if you sharing the parent's VM or not - if you are not then normally the best way is to use channels in nRoute (since they get away from the VisualTree part) else you can use binding and commands like normal. 

Hope this helps, if you are any more specific questions let me know.

Rishi

Jan 17, 2011 at 7:36 PM

Hi Rishi,

thanks for your help!

Helmut