/// <summary> /// Defines the template for core-level arrange layout definition. /// </summary> /// <remarks> /// In WPF this method is defined on UIElement as protected virtual and has a base implementation. /// FrameworkElement (which derrives from UIElement) creates a sealed implemention, similar to the below, /// which discards UIElement's base implementation. /// </remarks> /// <param name = "finalRect">The final area within the parent that element should use to arrange itself and its child elements.</param> private void ArrangeCore(BoundingRectangle finalRect) { Thickness margin = this.Margin; Vector2 unclippedDesiredSize = isClippingRequired ? unclippedSize : DesiredSize.Deflate(margin); Vector2 finalSize = new Vector2(finalRect.Width, finalRect.Height); finalSize = finalSize.Deflate(margin); isClippingRequired = false; if (finalSize.X < unclippedDesiredSize.X) { isClippingRequired = true; finalSize.X = unclippedDesiredSize.X; } if (finalSize.Y < unclippedDesiredSize.Y) { isClippingRequired = true; finalSize.Y = unclippedDesiredSize.Y; } if (HorizontalAlignment != HorizontalAlignment.Stretch) { finalSize.X = unclippedDesiredSize.X; } if (VerticalAlignment != VerticalAlignment.Stretch) { finalSize.Y = unclippedDesiredSize.Y; } var minMax = new MinMax(this); float largestWidth = Math.Max(unclippedDesiredSize.X, minMax.MaxWidth); if (largestWidth < finalSize.X) { finalSize.X = largestWidth; } float largestHeight = Math.Max(unclippedDesiredSize.Y, minMax.MaxHeight); if (largestHeight < finalSize.Y) { finalSize.Y = largestHeight; } Vector2 renderSize = this.ArrangeOverride(finalSize); this.RenderSize = renderSize; Vector2 inkSize = new Vector2( Math.Min(renderSize.X, minMax.MaxWidth), Math.Min(renderSize.Y, minMax.MaxHeight)); isClippingRequired |= inkSize.X < renderSize.X || inkSize.Y < renderSize.Y; Vector2 clientSize = finalRect.Size.Deflate(margin); isClippingRequired |= clientSize.X < inkSize.X || clientSize.Y < inkSize.Y; Vector2 offset = this.ComputeAlignmentOffset(clientSize, inkSize); offset.X += finalRect.X + margin.Left; offset.Y += finalRect.Y + margin.Top; this.visualOffset = offset; }