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

RebuildTable() private method

private RebuildTable ( ) : void
return void
        private void RebuildTable()
        {
            Children.Clear();
            if (ItemsSource == null || !(ItemsSource is IEnumerable))
                return;
            var list = (ItemsSource as IEnumerable).OfType<object>().ToList();
            int count = list.Count;
            int rows = currentRowCount;
            int cols = currentColumnCount;
            int itemSpace = rows * cols;
            bool hasLiveTile = false;
            if (count > itemSpace)
            {
                LiveTile tile = new LiveTile()
                {
                    ItemsSource = ItemsSource,
                    ItemTemplate = LiveTileItemTemplate,
                    Margin = new Thickness(0, 0, 20, 20)
                };
                tile.SetValue(Callisto.Effects.Tilt.IsTiltEnabledProperty, true);
                Children.Add(tile);
                hasLiveTile = true;
                tile.Tapped += livetile_Tapped;
            }
            int i = 0;
            for (int c = 0; c < cols; c++)
            {
                for (int r = 0; r < rows; r++)
                {
                    if (i >= list.Count)
                        break;
                    if (hasLiveTile && c < 2 && r < 2)
                        continue;
                    ContentControl ctrl = new ContentControl()
                    {
                        Content = list[i++],
                        ContentTemplate = ItemTemplate,
                        Margin = new Thickness(0, 0, 20, 20),
                        HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch,
                        VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch,
                        HorizontalContentAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch,
                        VerticalContentAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch
                    };
                    //ctrl.Transitions = new Windows.UI.Xaml.Media.Animation.TransitionCollection();
                    //ctrl.Transitions.Add(new Windows.UI.Xaml.Media.Animation.AddDeleteThemeTransition());
                    //ctrl.Transitions.Add(new Windows.UI.Xaml.Media.Animation.EntranceThemeTransition());
                    ctrl.SetValue(Callisto.Effects.Tilt.IsTiltEnabledProperty, true);
                    if (r == rows - 1 && c == Math.Min(cols, MaxColumnCount) - 1 &&
                        count > rows * cols) // last item
                    {
                        ctrl.ContentTemplate = MoreTemplate;
                        ctrl.Tapped += moreTile_Tapped;
                    }
                    else
                    {
                        ctrl.Tapped += ctrl_Tapped;
                    }
                    Children.Add(ctrl);
                }
            }
        }