private static Size GetAnchorPreferredSize(IArrangedElement container) { Size empty = Size.Empty; for (int i = container.Children.Count - 1; i >= 0; i--) { IArrangedElement element = container.Children[i]; if (!CommonProperties.GetNeedsDockLayout(element) && element.ParticipatesInLayout) { AnchorStyles anchor = GetAnchor(element); Padding margin = CommonProperties.GetMargin(element); Rectangle rectangle = LayoutUtils.InflateRect(GetCachedBounds(element), margin); if (IsAnchored(anchor, AnchorStyles.Left) && !IsAnchored(anchor, AnchorStyles.Right)) { empty.Width = Math.Max(empty.Width, rectangle.Right); } if (!IsAnchored(anchor, AnchorStyles.Bottom)) { empty.Height = Math.Max(empty.Height, rectangle.Bottom); } if (IsAnchored(anchor, AnchorStyles.Right)) { Rectangle rectangle2 = GetAnchorDestination(element, Rectangle.Empty, true); if (rectangle2.Width < 0) { empty.Width = Math.Max(empty.Width, rectangle.Right + rectangle2.Width); } else { empty.Width = Math.Max(empty.Width, rectangle2.Right); } } if (IsAnchored(anchor, AnchorStyles.Bottom)) { Rectangle rectangle3 = GetAnchorDestination(element, Rectangle.Empty, true); if (rectangle3.Height < 0) { empty.Height = Math.Max(empty.Height, rectangle.Bottom + rectangle3.Height); } else { empty.Height = Math.Max(empty.Height, rectangle3.Bottom); } } } } return(empty); }
private static Size GetAnchorPreferredSize(IArrangedElement container) { Size prefSize = Size.Empty; ArrangedElementCollection children = container.Children; for (int i = children.Count - 1; i >= 0; i--) { IArrangedElement element = container.Children[i]; if (!CommonProperties.GetNeedsDockLayout(element) && element.ParticipatesInLayout) { AnchorStyles anchor = GetAnchor(element); Padding margin = CommonProperties.GetMargin(element); Rectangle elementSpace = LayoutUtils.InflateRect(GetCachedBounds(element), margin); if (IsAnchored(anchor, AnchorStyles.Left) && !IsAnchored(anchor, AnchorStyles.Right)) { // If we are anchored to the left we make sure the container is large enough not to clip us // (unless we are right anchored, in which case growing the container will just resize us.) prefSize.Width = Math.Max(prefSize.Width, elementSpace.Right); } if (!IsAnchored(anchor, AnchorStyles.Bottom)) { // If we are anchored to the top we make sure the container is large enough not to clip us // (unless we are bottom anchored, in which case growing the container will just resize us.) prefSize.Height = Math.Max(prefSize.Height, elementSpace.Bottom); } if (IsAnchored(anchor, AnchorStyles.Right)) { // If we are right anchored, see what the anchor distance between our right edge and // the container is, and make sure our container is large enough to accomodate us. Rectangle anchorDest = GetAnchorDestination(element, Rectangle.Empty, /*measureOnly=*/ true); if (anchorDest.Width < 0) { prefSize.Width = Math.Max(prefSize.Width, elementSpace.Right + anchorDest.Width); } else { prefSize.Width = Math.Max(prefSize.Width, anchorDest.Right); } } if (IsAnchored(anchor, AnchorStyles.Bottom)) { // If we are right anchored, see what the anchor distance between our right edge and // the container is, and make sure our container is large enough to accomodate us. Rectangle anchorDest = GetAnchorDestination(element, Rectangle.Empty, /*measureOnly=*/ true); if (anchorDest.Height < 0) { prefSize.Height = Math.Max(prefSize.Height, elementSpace.Bottom + anchorDest.Height); } else { prefSize.Height = Math.Max(prefSize.Height, anchorDest.Bottom); } } } } return(prefSize); }