Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

ViewModel with bindable collections

David Sungaila edited this page Sep 18, 2020 · 1 revision

Let your class derive from PresentationBase.ViewModel. Create an ObservableViewModelCollection<> property and initialize it in your constructor.

public class AwesomeViewModel : ViewModel
{
    public ObservableViewModelCollection<ChildViewModel> Children { get; }
    
    public AwesomeViewModel()
    {
        Children = new ObservableViewModelCollection<ChildViewModel>(this);
        Children.Add(new ChildViewModel { Nickname = "Blinky" });
        Children.Add(new ChildViewModel { Nickname = "Pinky" });
        Children.Add(new ChildViewModel { Nickname = "Inky" });
        Children.Add(new ChildViewModel { Nickname = "Clyde" });
    }
}