Windows Phone 8 - MVVM ViewModels and App.xaml.cs

与世无争的帅哥 提交于 2019-12-05 05:43:26
anderZubi

There are many different approaches to instantiate ViewModels. Some of them will instantiate all at launch, while other don't instantiate the ViewModel until it is needed.

In the following blog post you will find some possible approaches to instantiate a ViewModel:

MVVM Instantiation Approaches

Answering your questions; 1.- Following your approach you would have to define members for all of your ViewModels in your App.xaml.cs file. 2.- You can follow an approach that doesn't instantiate the ViewModel until it is needed.

There exist some toolkits, such MVVM Light or Caliburn Micro, that ease the implementation of MVVM pattern. I personally use MVVM Light Toolkit, which uses the Locator approach. Using this toolkit, ViewModels are loaded when needed by default, but you can set it to load a specific ViewModel at launch, which can be useful in some scenarios.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!