Is there an alternative to a WPF WrapPanel that wr

2019-08-04 17:36发布

问题:

Normally a WPF WrapPanel (Orientation="Vertical") will stack items vertically (and grow vertically) until it runs out of space from the parent container, and then it will "wrap" to the next column.

I want this functionality, but I want to add a hard limit to the number of items in a column. For instance, if my height is 100 and I have 3 items that are 30 pixels high, normally it could fit them all without wrapping. However, say I want to force it to wrap after 2. In that case, I want it to only grow to a height of 60, and wrap the 3rd item into the second column.

Is there something I can do to make this happen?

回答1:

Maybe you can do it with the UniformGrid.
Use the Rows property to definie the amount of elements in vertical direction.



回答2:

here is a nice little article about the available layout panels in WPF. If one of these does not fit the bill, you might have to build your own custom panel, here is a decent demo.



标签: wpf wrappanel