XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWorkflow

【WinUI】XFE基于windows的工作流

公开
关注 0 Fork 0 Star 0
UTF-8
using Windows.Foundation;

namespace XFEWorkflow.Controls;

public sealed class AdaptiveWrapPanel : Panel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        var x = 0d; var y = 0d; var rowHeight = 0d; var width = 0d;
        foreach (var child in Children.Where(x => x.Visibility != Visibility.Collapsed))
        {
            child.Measure(new(availableSize.Width, availableSize.Height));
            var size = child.DesiredSize;
            if (x > 0 && x + size.Width > availableSize.Width) { width = Math.Max(width, x - 8); y += rowHeight + 8; x = rowHeight = 0; }
            x += size.Width + 8; rowHeight = Math.Max(rowHeight, size.Height);
        }
        return new(Math.Min(availableSize.Width, Math.Max(width, Math.Max(0, x - 8))), y + rowHeight);
    }
    protected override Size ArrangeOverride(Size finalSize)
    {
        var x = 0d; var y = 0d; var rowHeight = 0d;
        foreach (var child in Children.Where(x => x.Visibility != Visibility.Collapsed))
        {
            var size = child.DesiredSize;
            if (x > 0 && x + size.Width > finalSize.Width) { y += rowHeight + 8; x = rowHeight = 0; }
            child.Arrange(new(x, y, Math.Min(size.Width, finalSize.Width), size.Height)); x += size.Width + 8; rowHeight = Math.Max(rowHeight, size.Height);
        }
        return finalSize;
    }
}