0
votes

I've completed some simple MVVM tutorials, but they were super simplified examples. Here is my problem: I have a model class for a person, which contains some variables (firstname, lastname) and lists (education, workplaces). These lists have their own classes. For simple variables I created one viewmodel which implements INotifyPropertyChanged interface and everything works pretty well. However I don't know how to handle the lists. Should they have seperate viewmodels? Or how can I add these to the existing ViewModel?

Thanks in advance!

3

3 Answers

2
votes

If you need to more actions on elements of those collection then you can create separate ViewModels for those classes. Then in general ViewModel you can create ObservableCollection of additional ViewModels.

Pseudo code:

public class PersonViewModel
{
    public ObservableCollection<EducationViewModel> Education { get; set; }
    public ObservableCollection<WorkplaceViewModel> Workplaces { get; set; }
}
0
votes

For starters, implementing the list as an ObservableCollection on your ViewModel will work fine. There's an example on MSDN to get you started; there are tons of tutorials around too.

0
votes

If the view present a list of things, then having a Collection as the vie model is fine in order to me. Probably you need to have the collection "Observable", by implementing INotifyCollectionChanged or by deriving from ObservableCollection<>.