8
votes

Which one is the better solution to hold my data or does it depends on some conditions?

sample situation 1:
you need to display a list of data which can be modified in an new window after selection.

sample situation 2:
you need to display a list of data which can be modified in this list.

2

2 Answers

10
votes

As you're using MVVM, you should be going with ObservableCollection<ViewModel>.

The Model should be separated from the View by means of the ViewModel.

0
votes

I would say go with ObservableCollection<Model> since it is something that you can bind directly to the List or datagrid.

For Sample Situation 1 : Select a Model and then set the data context of the new Window to that Model.

For Sample Situation 2 : In place editing of the datagrid with 2 way binding.

The ObservableCollection can be inside a ViewModel. Something like the one shown below.

public class MyViewModel
{
     public ObservableCollection<Model> ListOfItems { get; set;}
}