ArcGISPortalViewer.Controls.GalleryPreviewControl.ArrangeOverride C# (CSharp) Method

ArrangeOverride() protected method

Provides the behavior for the Arrange pass of layout. Classes can override this method to define their own Arrange pass behavior.
protected ArrangeOverride ( Size finalSize ) : Size
finalSize Windows.Foundation.Size The final area within the parent that this object should use to arrange itself and its children.
return Windows.Foundation.Size
        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);
        }