Is there an alternative to a WPF WrapPanel that wraps after a certain number of items, not a height?

跟風遠走 提交于 2019-12-11 05:03:22

问题


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.



来源:https://stackoverflow.com/questions/7434444/is-there-an-alternative-to-a-wpf-wrappanel-that-wraps-after-a-certain-number-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!