This project has moved. For the latest updates, please go here.

Creating a Non-Shared View Model

There are times when you must generate a new copy of a view model instead of using the default, shared view model that Jounce provides. This is not a problem. In fact, because Jounce provides a "lazy load" service for view models, if you have certain view models that are only non-shared, a single copy will never be generated unless you ask for one. The built-in navigation and view routing system supports the shared model. For non-shared, simply import an instance of IViewModelRouter:

[Import]
public IViewModelRouter Router { get; set; }

This is already provided for you in the base view model class.

Next, simply pass the view model tag and request a non-shared copy:

var vm = Router.GetNonSharedViewModel("MyViewModelTag");

If you export view models using types, you can use the type-safe version (the tag is passed as the full type name) like this:

var vm = Router.GetNonSharedViewModel<MyViewModel>();

That's it - you now have a new copy of the view model to use.

Last edited Mar 27, 2011 at 8:08 PM by jeremylikness, version 14

Comments

No comments yet.