public override Size Measure(Size availableSize) { double maxWidth = 0; double totalHeight = 0; double availableWidth = availableSize.Width; double rowHeight = 0; foreach(var child in children) { var size = child.Measure(availableSize); if (size.Width > availableWidth) { //break and start a new row maxWidth = Math.Max(maxWidth, availableSize.Width - availableWidth); totalHeight += rowHeight; availableWidth = availableSize.Width - size.Width; rowHeight = size.Height; } else { //add to current row availableWidth -= size.Width; rowHeight = Math.Max(rowHeight, size.Height); } } //add last row maxWidth = Math.Max(maxWidth, availableSize.Width - availableWidth); totalHeight += rowHeight; return new Size(maxWidth, totalHeight); }
public override Size Measure(Size availableSize) { return new Size(Width + Margin.Left + Margin.Right, Height + Margin.Top + Margin.Bottom); }