MVVM and nested view models

You are on the right track.

The parent model would naturally contain a list of child models, e.g. a customer having multiple orders.

When ParentViewModel is created and loaded by a third-party, it is passed a ParentModel. Then the ParentViewModel will:

  1. Assign the ParentModel to a local variable
  2. Create a ChildViewModel for each ChildModel by passing the
    ChildModel to the ChildViewModel constructor
  3. Add each of those ChildViewModels to a list

By the way, you want

public List<ChildViewModel> ChildViewModels { get; set; }

to be

public ObservableCollection<ChildViewModel> ChildViewModels { get; set; }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)