开发者

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 te开发者_开发问答mplate 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.


ItemsControl is your friend:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜