WPF List of ViewModels bound to list of Model objects.

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2010-05-17T22:15:44Z Indexed on 2010/05/17 22:20 UTC
Read the original article Hit count: 177

In the model, I have:

public ObservableCollection<Item> Items { get; private set; }

In the ViewModel, I have a corresponding list of ItemViewModels:

public ObservableCollection<ItemViewModel> ItemViewModels ...

In the XAML, I will bind (in this case a TreeView) to the ItemViewModels property.

My question is, what goes in the "..." in the ViewModel shown above? I am hoping for a line or two of code to binds these two ObservableCollections (providing the type of the ViewModel to construct for each model object). However, what I'm fearing is necessary is a bunch of code to handle the Items.CollectionChanged event and manually updates the ItemViewModels list by constructing ViewModels as necessary.

Thanks!

Eric

© Stack Overflow or respective owner

Related posts about model-view-viewmodel

Related posts about wpf