开发者

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

开发者 https://www.devze.com 2022-12-18 21:23 出处:网络
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开发者_开

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

精彩评论

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