Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 663
Vaccano Avatar asked Jan 31 '10 20:01

Vaccano


1 Answers

ItemsControl is your friend:

<ItemsControl ItemsSource="{Binding YourChildItems}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>
like image 159
Kent Boogaart Avatar answered Nov 04 '22 23:11

Kent Boogaart