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

MeasureOverride() protected method

Provides the behavior for the Measure pass of the layout cycle. Classes can override this method to define their own Measure pass behavior.
protected MeasureOverride ( Size availableSize ) : Size
availableSize Windows.Foundation.Size The available size that this object can give to child objects. Infinity can be /// specified as a value to indicate that the object will size to whatever content is available.
return Windows.Foundation.Size
        protected override Size MeasureOverride(Size availableSize)
        {
            if (ItemsSource == null)
                return new Size(0, 0);
            var list = (ItemsSource as IEnumerable).OfType<object>().ToList();
            int count = list.Count;
            CalculateRowColumnCount(availableSize, count);

            foreach (var item in Children)
            {
                if (item is Callisto.Controls.LiveTile)
                    item.Measure(new Size(ColumnWidth * 2, RowHeight * 2));
                else
                    item.Measure(new Size(ColumnWidth, RowHeight));
            }

            //If this is an incremental loading datasource, see if we can get enough to fill up and show more... tile.
            if (ItemsSource is Windows.UI.Xaml.Data.ISupportIncrementalLoading)
            {
                var maxTileSpace = Math.Min(MaxColumnCount, Math.Ceiling(availableSize.Width / ColumnWidth)) * Math.Ceiling(availableSize.Height / RowHeight);
                if (count <= maxTileSpace)
                {
                    var iloading = (ItemsSource as Windows.UI.Xaml.Data.ISupportIncrementalLoading);
                    if (iloading.HasMoreItems)
                    {
                        var loadmoreTask = iloading.LoadMoreItemsAsync((uint)maxTileSpace + 1);
                    }
                }
            }

            return new Size(currentColumnCount * ColumnWidth, currentRowCount * RowHeight);
        }