Create All viewModels on Startup

Apr 3, 2014 at 8:59 AM
Hello

Is it possible to create all Viewmodels at startup.

I use catel:UserControls with injected Viewmodels. I have 3 views with according viewmodels. First time I navigate to any view I have to wait. Its not fast and fluid.

So is it possible to load all views with viewmodels at startup.
Coordinator
Apr 3, 2014 at 9:00 AM
View models are created on demand because they are context-sensitive (With model injection). Luckily for you the ViewModelFactory is registered in the ServiceLocator so you can simply write your own that caches view models (but then the side-effects that causes this are also your own responsibility).
Apr 3, 2014 at 12:41 PM
ok. Is it also possible to use a catel usercontrol which don't creates a new viewmodel use instead the parent viewmodel?
Coordinator
Apr 3, 2014 at 10:01 PM
Yes, when they are the view model (e.g. PersonWindow (with PersonViewModel) and PersonView (with PersonViewModel), the view model will be shared. But again, you can fully take control using the ViewModelFactory (and just return anything you like).