简体   繁体   中英

Using MVVM Light, ViewModelLocator hold all ViewModels?

I'm using MVVM Light.

This is my scenario:

I want to add one or more student through a window, and there are two ways to achieve this. The first is to list all students(displaying UserControl1), and the other is to manually input the student's name (displaying UserControl2).

The Window consist of a ContentControl (which is one of two UserControl s) and some Button s on the bottom.

在此处输入图片说明

The Window and two different UserControl corresponds 3 different Viewmodels(AddStudentsViewModel, AutoScanStudentsViewModel and ManuallyAddStudentViewModel).

I'm new to MVVM, so I can't determine if to put 3 ViewModels all in ViewModelLocator or put the 2 latter ViewModels in AddStudentsViewModel?

For the specific example that you have given, I would expose the latter 2 ViewModels as properties of the AddStudentsViewModel.

However, if it was valid for the latter 2 ViewModels to be shown on their own, ie in a PopupWindow, there would be no reason why you couldn't add them to your ViewModelLocator as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM