Created
October 29, 2015 18:56
-
-
Save jonstodle/8310047ead1aea5698fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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