How to bind an observable collection to an array of user controls?

data-binding, mvvm, observablecollection, wpf

Solution

Use an `ItemsControl` and a `DataTemplate`

<ItemsControl ItemsSource="{Binding YourCollection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <uc:YourUserControl />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Problem

Databinding in WPF is great, but the moment you try make things more complex it gets exceedingly difficult to implement things. I have a collection of objects, where each object has observable properties that are bound to a user control. I would like to (ideally) simply add a new object to my collection, and have a new user control appear on my form. The thing is user controls need to be dynamically created, so each time I add to the collection I may have to manually create a new control, set the binding and add it to my Window. Is there a simpler MVVM style way of binding to such a structure?

Original source