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

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

问题描述

我有一个WrapPanel,我想指定它的列的最大数量。所以,例如,当我的CollectionObjectCollection(绑定到这个WrapPanel)只包含4个元素时,WrapPanel将只有一行。但是,当ObjectCollection将有5个元素时,wrapPanel将创建另一行来放置第五个元素。 (我的Max_Columns_Number在这种情况下是4)。



有没有人有这样的想法?

解决方案

我很确定你不能用 WrapPanel ,但您可以使用 UniformGrid



该属性具有指定所需行数和列数的属性。 p>

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

 < UniformGrid Columns =4> 
<! - 第一行 - >
< Button Content =test>< / Button>
< Button Content =test>< / Button>
< Button Content =test>< / Button>
< Button Content =test>< / Button>

<! - 第二行 - >
< Button Content =test>< / Button>
< / UniformGrid>


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).

Does anyone have an idea of how to do that ?

解决方案

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.

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天全站免登陆