SubmarineX
SubmarineX

Reputation: 850

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 UserControls) and some Buttons on the bottom.

enter image description here

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?

Upvotes: 0

Views: 436

Answers (1)

Peter Holmes
Peter Holmes

Reputation: 652

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, i.e. in a PopupWindow, there would be no reason why you couldn't add them to your ViewModelLocator as well.

Upvotes: 1

Related Questions