Exemplo n.º 1
0
 protected override Size ArrangeOverride(Size arrangeSize)
 {
     foreach (UIElement child in Children)
     {
         var childRow    = HexagonalGrid.GetRow(child);
         var childColumn = HexagonalGrid.GetColumn(child);
         var xPos        = childColumn * _childSize.Width * 0.75;
         var yPos        = _childSize.Height * (childRow + (this.IsOffsetColumn(childColumn) ? 0.5 : 0));
         child.Arrange(new Rect(xPos, yPos, _childSize.Width, _childSize.Height));
     }
     return(arrangeSize);
 }
Exemplo n.º 2
0
        protected override Size MeasureOverride(Size availableSize)
        {
            var hexRectBounds = new Size(0, 0);
            var maxRow        = 1;
            var maxColumn     = 1;

            if (GridEdgeLength.IsAuto || GridEdgeLength.IsStar)
            {
                foreach (UIElement child in Children)
                {
                    child.Measure(InfiniteSize);
                    hexRectBounds.Width  = Math.Max(hexRectBounds.Width, child.DesiredSize.Width);
                    hexRectBounds.Height = Math.Max(hexRectBounds.Height, child.DesiredSize.Height);
                    maxRow    = Math.Max(maxRow, HexagonalGrid.GetRow(child));
                    maxColumn = Math.Max(maxColumn, HexagonalGrid.GetColumn(child));
                }
            }
            else
            {
                hexRectBounds = new Size(GridEdgeLength.Value * 2, GridEdgeLength.Value * 2 * HexMinRadiusToMaxRadiusRatio);

                foreach (UIElement child in Children)
                {
                    child.Measure(hexRectBounds);
                }
            }

            _childSize = hexRectBounds;

            var cols = (Columns == 0 ? maxColumn : Columns) * 0.75 + 0.25;
            var rows = (Rows == 0 ? maxRow : Rows) + 0.5;

            var resultSize = new Size(_childSize.Width * cols, _childSize.Height * rows);

            resultSize.Width = double.IsPositiveInfinity(availableSize.Width)
                                   ? resultSize.Width
                                   : availableSize.Width;

            resultSize.Height = double.IsPositiveInfinity(availableSize.Height)
                                    ? resultSize.Height
                                    : availableSize.Height;

            return(resultSize);
        }