WPF - Bind a List<T> as the contents of a WrapPanel

binding, c#, data-binding, wpf

Solution

`ItemsControl` is your friend:

<ItemsControl ItemsSource="{Binding YourChildItems}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

Problem

Is is possible to make the contents(children) of a WrapPanel to be bound to a dependency property? What I am thinking is having a dependency property that is of type List and then define a template for MyClass. Then have the WrapPanel display them. I know this is much easier done with a list box, but due to other constraints, I need to try with a WrapPanel before going to a list box. I am using MVVM. I would prefer doing this in that pattern. If I were to break out of MVVM I could just use an event or name it and fill it at load time. I am hoping there is a binding way that is cleaner.

Original source