Ejemplo n.º 1
0
        protected override SizeF MeasureItems(SizeF availableSize)
        {
            SizeF desiredSize = SizeF.Empty;

            this.layoutInfo = this.CreateLayoutInfo(availableSize);
            StackViewPosition stackPosition = this.layoutInfo.position;

            switch (stackPosition)
            {
            case StackViewPosition.Bottom:
            case StackViewPosition.Top:
                this.ApplyItemMetricsHorizontal();
                break;

            case StackViewPosition.Left:
            case StackViewPosition.Right:
                this.ApplyItemMetricsVertical();
                break;
            }

            this.MeasureItemsCore();

            if (stackPosition == StackViewPosition.Top || stackPosition == StackViewPosition.Bottom)
            {
                availableSize.Height -= layoutInfo.layoutLength;
                desiredSize.Height    = layoutInfo.layoutLength;
                desiredSize.Width     = layoutInfo.maxWidth;
            }
            else
            {
                availableSize.Width -= layoutInfo.layoutLength;
                desiredSize.Width    = layoutInfo.layoutLength;
                desiredSize.Height   = layoutInfo.maxHeight;
            }

            SizeF contentAreaDesiredSize = MeasureContentArea(ref availableSize);

            if (stackPosition == StackViewPosition.Top || stackPosition == StackViewPosition.Bottom)
            {
                desiredSize.Height += contentAreaDesiredSize.Height;
                desiredSize.Width   = Math.Max(desiredSize.Width, contentAreaDesiredSize.Width);
            }
            else
            {
                desiredSize.Width += contentAreaDesiredSize.Width;
                desiredSize.Height = Math.Max(desiredSize.Height, contentAreaDesiredSize.Height);
            }

            return(desiredSize);
        }
Ejemplo n.º 2
0
        protected override SizeF MeasureItems(SizeF availableSize)
        {
            SizeF empty = SizeF.Empty;

            this.layoutInfo = this.CreateLayoutInfo(availableSize);
            StackViewPosition position = this.layoutInfo.position;

            switch (position)
            {
            case StackViewPosition.Left:
            case StackViewPosition.Right:
                this.ApplyItemMetricsVertical();
                break;

            case StackViewPosition.Top:
            case StackViewPosition.Bottom:
                this.ApplyItemMetricsHorizontal();
                break;
            }
            this.MeasureItemsCore();
            if (position == StackViewPosition.Top || position == StackViewPosition.Bottom)
            {
                availableSize.Height -= this.layoutInfo.layoutLength;
                empty.Height          = this.layoutInfo.layoutLength;
                empty.Width           = this.layoutInfo.maxWidth;
            }
            else
            {
                availableSize.Width -= this.layoutInfo.layoutLength;
                empty.Width          = this.layoutInfo.layoutLength;
                empty.Height         = this.layoutInfo.maxHeight;
            }
            SizeF sizeF = this.MeasureContentArea(ref availableSize);

            if (position == StackViewPosition.Top || position == StackViewPosition.Bottom)
            {
                empty.Height += sizeF.Height;
                empty.Width   = Math.Max(empty.Width, sizeF.Width);
            }
            else
            {
                empty.Width += sizeF.Width;
                empty.Height = Math.Max(empty.Height, sizeF.Height);
            }
            return(empty);
        }