Skip to content

Instantly share code, notes, and snippets.

@jonstodle
Created October 28, 2015 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonstodle/c808ae68fa58e050c2c5 to your computer and use it in GitHub Desktop.
Save jonstodle/c808ae68fa58e050c2c5 to your computer and use it in GitHub Desktop.
protected override Size MeasureOverride(Size availableSize)
{
// Set it to use whole available width
var finalSize = new Size { Width = availableSize.Width };
var columnWidth = availableSize.Width / MaximumColumns;
var rowHeight = 0d;
var rowChildCount = 0;
foreach (var child in Children)
{
child.Measure(new Size(columnWidth, availableSize.Height));
if (rowChildCount < MaximumColumns)
{
// Get the talles element in the row to make sure the next row is below all elements on this row
rowHeight = Math.Max(child.DesiredSize.Height, rowHeight);
}
else
{
// New row
finalSize.Height += rowHeight;
rowHeight = child.DesiredSize.Height;
rowChildCount = 0;
}
rowChildCount++;
}
// Add height of last row
finalSize.Height += rowHeight;
return finalSize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment