/// <summary> /// When overridden in a derived class, measures the size in layout required for child elements and determines a size for the <see cref="T:System.Windows.FrameworkElement" />-derived class. /// </summary> /// <param name="availableSize">The available size that this element can give to child elements. Infinity can be specified as a value to indicate that the element will size to whatever content is available.</param> /// <returns> /// The size that this element determines it needs during layout, based on its calculations of child element sizes. /// </returns> protected override Size MeasureOverride(Size availableSize) { var worldLayer = World; var viewportLayer = this; if (worldLayer == null) return new Size(); foreach (UIElement child in InternalChildren) { if (child == null) continue; var left = GetLeft(child); var top = GetTop(child); var right = GetRight(child); var bottom = GetBottom(child); var rect = new Rect(0, 0, Math.Abs(right - left), Math.Abs(bottom - top)); var constraint = rect.Translate(worldLayer, viewportLayer).Size; if (double.IsNaN(constraint.Width)) constraint.Width = double.PositiveInfinity; if (double.IsNaN(constraint.Height)) constraint.Height = double.PositiveInfinity; child.Measure(constraint); } return new Size(); }