Ejemplo n.º 1
0
        protected int LayoutTileColumn(int columnIndex, int startIndex, int maxVerticalCellCount, int maxHorizontalCellCount, ref int rowCount)
        {
            maxVerticalCellCount = Math.Max(2, maxVerticalCellCount);
            int currentColumn = 0;
            int currentRow    = 0;
            int rowSpan       = 0;

            rowCount = 0;
            for (int i = startIndex; i < Children.Count; i++)
            {
                TileSize tileSize   = VerticalTilePanel.GetTileSize(Children[i]);
                int      columnSpan = tileSize == TileSize.Small ? 1 : 2;
                if (columnSpan > maxHorizontalCellCount)
                {
                    return(-1);
                }
                if (currentColumn + columnSpan > maxHorizontalCellCount)
                {
                    currentRow   += rowSpan;
                    rowCount     += rowSpan;
                    currentColumn = 0;
                }
                rowSpan = tileSize == TileSize.Large ? 2 : 1;
                if (currentRow + rowSpan > maxVerticalCellCount)
                {
                    return(i - 1);
                }
                VerticalTilePanel.SetColumn(Children[i], columnIndex + currentColumn);
                VerticalTilePanel.SetRow(Children[i], currentRow);
                currentColumn += columnSpan;
            }

            return(Children.Count - 1);
        }
Ejemplo n.º 2
0
        protected override Size MeasureOverride(Size availableSize)
        {
            int maxVerticalCellCount = Math.Max(1, (int)(double.IsInfinity(availableSize.Height) ? 100 : availableSize.Height / SmallTileHeight));
            int startIndex           = 0;
            int columnIndex          = 0;
            int rowCount             = 0;

            while (startIndex != Children.Count)
            {
                int newIndex = LayoutTileColumn(columnIndex, startIndex, maxVerticalCellCount, 1, ref rowCount);
                columnIndex++;
                if (newIndex == -1)
                {
                    newIndex = LayoutTileColumn(columnIndex - 1, startIndex, maxVerticalCellCount, 2, ref rowCount);
                    if (newIndex == -1)
                    {
                        throw new InvalidOperationException();
                    }
                    columnIndex++;
                }
                if (startIndex == 0)
                {
                    maxVerticalCellCount = Math.Min(rowCount, maxVerticalCellCount);
                }
                startIndex = newIndex + 1;
            }
            foreach (UIElement child in Children)
            {
                TileSize tileSize   = VerticalTilePanel.GetTileSize(child);
                int      rowSpan    = tileSize == TileSize.Large ? 2 : 1;
                int      columnSpan = tileSize == TileSize.Small ? 1 : 2;
                child.Measure(new Size(columnSpan * SmallTileWidth, rowSpan * SmallTileHeight));
            }
            return(new Size(SmallTileWidth * columnIndex, SmallTileHeight * maxVerticalCellCount));
        }
Ejemplo n.º 3
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     foreach (UIElement child in Children)
     {
         TileSize tileSize   = VerticalTilePanel.GetTileSize(child);
         int      rowSpan    = tileSize == TileSize.Large ? 2 : 1;
         int      columnSpan = tileSize == TileSize.Small ? 1: 2;
         child.Arrange(new Rect(VerticalTilePanel.GetColumn(child) * SmallTileWidth, VerticalTilePanel.GetRow(child) * SmallTileHeight, columnSpan * SmallTileWidth, rowSpan * SmallTileHeight));
     }
     return(finalSize);
 }