Created
October 28, 2015 10:33
-
-
Save jonstodle/c808ae68fa58e050c2c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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