指定WPF中WrapPanel的最大列数 [英] Specify the max number of columns for a WrapPanel in WPF

查看:192
本文介绍了指定WPF中WrapPanel的最大列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WrapPanel,并且我想指定其最大列数.因此,例如,当我的集合"ObjectCollection"(绑定到此WrapPanel)仅包含4个元素时,WrapPanel将只有一行.但是,当"ObjectCollection"具有5个元素时,wrapPanel将创建另一行以放置第五行. (在这种情况下,我的Max_Columns_Number是4).

I have a WrapPanel, And I want to specify the Max number of its columns. So, for example, when my Collection "ObjectCollection" (binded to this WrapPanel) contains only 4 elements, the WrapPanel will have only one row. But, when "ObjectCollection" will have 5 elements, the wrapPanel will create another row to put the fifth one. (My Max_Columns_Number in this case is 4).

推荐答案

我很确定您不能使用

I'm pretty sure you can't do it with a WrapPanel, but you can use the UniformGrid instead.

该属性具有指定所需行和列数的属性.

That one has properties to specify the number of rows and columns you want.

如果将Columns属性设置为4,它将在每行中保留4个项目,然后包装到下一个项目.

If you set the Columns property to 4, it will keep 4 items in each row, and then wrap to the next one.

<UniformGrid Columns="4">
    <!-- In first row -->
    <Button Content="test"></Button>
    <Button Content="test"></Button>
    <Button Content="test"></Button>
    <Button Content="test"></Button>

    <!-- In second row -->
    <Button Content="test"></Button>
</UniformGrid>

这篇关于指定WPF中WrapPanel的最大列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆