Skip to content

Instantly share code, notes, and snippets.

@jonstodle
Created October 29, 2015 18:56
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/8310047ead1aea5698fd to your computer and use it in GitHub Desktop.
Save jonstodle/8310047ead1aea5698fd to your computer and use it in GitHub Desktop.
protected override Size ArrangeOverride(Size finalSize)
{
var posY = 0d;
var currentRow = new List<UIElement>();
var rowHeight = 0d;
foreach (var child in Children)
{
if (currentRow.Sum(x => x.DesiredSize.Width) + child.DesiredSize.Width <= finalSize.Width)
{
currentRow.Add(child);
rowHeight = Math.Max(child.DesiredSize.Height, rowHeight);
}
else
{
var rowChildCount = currentRow.Count;
var columnWidth = finalSize.Width / rowChildCount;
for (int i = 0; i < rowChildCount; i++)
{
currentRow[i].Arrange(new Rect(columnWidth * i, posY, columnWidth, currentRow[i].DesiredSize.Height));
}
posY += rowHeight;
rowHeight = child.DesiredSize.Height;
currentRow = new List<UIElement>();
currentRow.Add(child);
}
}
if (currentRow.Count > 0)
{
var rowChildCount = currentRow.Count;
var columnWidth = finalSize.Width / Math.Max(rowChildCount, MinimumColumnsOnLastRow);
for (int i = 0; i < rowChildCount; i++)
{
currentRow[i].Arrange(new Rect(columnWidth * i, posY, columnWidth, currentRow[i].DesiredSize.Height));
}
}
return finalSize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment