是否有 WPF“WrapGrid"?控制可用还是创建一个简单的方法?

编程入门 行业动态 更新时间:2024-10-18 16:42:40
本文介绍了是否有 WPF“WrapGrid"?控制可用还是创建一个简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

基本上我想要一个 wrapPanel,但我希望项目捕捉到网格而不是被压到左边,所以我可以获得一个漂亮的统一网格,它会自动消耗可用空间.

Essentially I want a wrapPanel, but I would like items to snap to a grid rather than be pressed up to the left, so I can get a nice uniform looking grid, that automatically consumes available space.

WrapPanel 处理调整大小部分.WPF.Contrib.AutoGrid 处理一个不错的自动网格.

WrapPanel handles the resize part. WPF.Contrib.AutoGrid handles a nice automatic grid.

任何人有组合它们的控件吗?

Anyone got a control that combines them?

我的用例是我有一系列形状不规则的控件.我希望它们出现在漂亮的列中,以便在放置控件时自动换行面板应该捕捉到下一个制表位"

My use case is I have a series of somewhat irregularly shaped controls. I would like them to appear in nice columns so the wrap panel should snap to the next "tabstop" when placing a control

推荐答案

这是我根据其他一些关闭的控件编写的一些代码.它在布局方面做得不错,尽管存在孙控件无法填满所有可用空间的问题.

Here is some code that I whipped up based on some of the other controls that are close. It does a decent job of doing the layout, although it has an issue where grand-child controls do not fill up all their available space.

protected override Size ArrangeOverride(Size finalSize) { double rowY = 0; int col = 0; double currentRowHeight = 0; foreach (UIElement child in Children) { var initialSize = child.DesiredSize; int colspan = (int) Math.Ceiling(initialSize.Width/ ColumnSize); Console.WriteLine(colspan); double width = colspan * ColumnSize; if (col > 0 && (col * ColumnSize) + width > constrainedSize.Width) { rowY += currentRowHeight; col = 0; currentRowHeight = 0; } var childRect = new Rect(col * ColumnSize, rowY, width, initialSize.Height); child.Arrange(childRect); currentRowHeight = Math.Max(currentRowHeight, initialSize.Height); col+=colspan; } return finalSize; } Size constrainedSize; protected override Size MeasureOverride(Size constraint) { constrainedSize = constraint; return base.MeasureOverride(constraint); }

更多推荐

是否有 WPF“WrapGrid"?控制可用还是创建一个简单的方法?

本文发布于:2023-11-07 05:51:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   简单   方法   WPF   WrapGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!