protected override Size ArrangeOverride(Size finalSize)
{
if (ItemsSource == null)
return new Size(0, 0);
var list = (ItemsSource as IEnumerable).OfType<object>().ToList();
int count = list.Count;
CalculateRowColumnCount(finalSize, count);
int MaxChildCount = currentRowCount * currentColumnCount;
bool hasLiveTile = count > MaxChildCount;
if (Children.Count != Math.Min(currentRowCount * currentColumnCount - (hasLiveTile ? 3 : 0), count))
{
RebuildTable();
}
int i = 0;
int row = 0;
int column = 0;
hasLiveTile = false;
foreach (var item in Children)
{
if (item is LiveTile && i == 0)
{
hasLiveTile = true;
item.Arrange(new Rect(0, 0, ColumnWidth * 2, RowHeight * 2));
row++;
}
else
{
item.Arrange(new Rect(column * ColumnWidth, row * RowHeight, ColumnWidth, RowHeight));
}
row++;
if (row >= currentRowCount)
{
column++;
if (hasLiveTile && column == 1)
row = 2;
else
row = 0;
if (column >= currentColumnCount)
break;
}
}
return new Size(currentColumnCount * ColumnWidth, currentRowCount * RowHeight);
}