npalotai
npalotai

Reputation: 3

Silverlight MVVM question

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!

Upvotes: 0

Views: 107

Answers (3)

Rafal Spacjer
Rafal Spacjer

Reputation: 4918

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; }
}

Upvotes: 2

Felice Pollano
Felice Pollano

Reputation: 33272

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<>.

Upvotes: 0

Jon
Jon

Reputation: 437774

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.

Upvotes: 0

Related Questions