//------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- #region Protected Methods /// <summary> /// Updates DesiredSize of the DockPanel. Called by parent UIElement. This is the first pass of layout. /// </summary> /// <remarks> /// Children are measured based on their sizing properties and <see cref="System.Windows.Controls.Dock" />. /// Each child is allowed to consume all of the space on the side on which it is docked; Left/Right docked /// children are granted all vertical space for their entire width, and Top/Bottom docked children are /// granted all horizontal space for their entire height. /// </remarks> /// <param name="constraint">Constraint size is an "upper limit" that the return value should not exceed.</param> /// <returns>The Panel's desired size.</returns> protected override Size MeasureOverride(Size constraint) { UIElementCollection children = InternalChildren; double parentWidth = 0; // Our current required width due to children thus far. double parentHeight = 0; // Our current required height due to children thus far. double accumulatedWidth = 0; // Total width consumed by children. double accumulatedHeight = 0; // Total height consumed by children. for (int i = 0, count = children.Count; i < count; ++i) { UIElement child = children[i]; Size childConstraint; // Contains the suggested input constraint for this child. Size childDesiredSize; // Contains the return size from child measure. if (child == null) { continue; } // Child constraint is the remaining size; this is total size minus size consumed by previous children. childConstraint = new Size(Math.Max(0.0, constraint.Width - accumulatedWidth), Math.Max(0.0, constraint.Height - accumulatedHeight)); // Measure child. child.Measure(childConstraint); childDesiredSize = child.DesiredSize; // Now, we adjust: // 1. Size consumed by children (accumulatedSize). This will be used when computing subsequent // children to determine how much space is remaining for them. // 2. Parent size implied by this child (parentSize) when added to the current children (accumulatedSize). // This is different from the size above in one respect: A Dock.Left child implies a height, but does // not actually consume any height for subsequent children. // If we accumulate size in a given dimension, the next child (or the end conditions after the child loop) // will deal with computing our minimum size (parentSize) due to that accumulation. // Therefore, we only need to compute our minimum size (parentSize) in dimensions that this child does // not accumulate: Width for Top/Bottom, Height for Left/Right. switch (DockPanel.GetDock(child)) { case Dock.Left: case Dock.Right: parentHeight = Math.Max(parentHeight, accumulatedHeight + childDesiredSize.Height); accumulatedWidth += childDesiredSize.Width; break; case Dock.Top: case Dock.Bottom: parentWidth = Math.Max(parentWidth, accumulatedWidth + childDesiredSize.Width); accumulatedHeight += childDesiredSize.Height; break; } } // Make sure the final accumulated size is reflected in parentSize. parentWidth = Math.Max(parentWidth, accumulatedWidth); parentHeight = Math.Max(parentHeight, accumulatedHeight); return(new Size(parentWidth, parentHeight)); }
/// <summary> /// DockPanel computes a position and final size for each of its children based upon their /// <see cref="System.Windows.Controls.Dock" /> enum and sizing properties. /// </summary> /// <param name="arrangeSize">Size that DockPanel will assume to position children.</param> protected override Size ArrangeOverride(Size arrangeSize) { UIElementCollection children = InternalChildren; int totalChildrenCount = children.Count; int nonFillChildrenCount = totalChildrenCount - (LastChildFill ? 1 : 0); double accumulatedLeft = 0; double accumulatedTop = 0; double accumulatedRight = 0; double accumulatedBottom = 0; for (int i = 0; i < totalChildrenCount; ++i) { UIElement child = children[i]; if (child == null) { continue; } Size childDesiredSize = child.DesiredSize; Rect rcChild = new Rect( accumulatedLeft, accumulatedTop, Math.Max(0.0, arrangeSize.Width - (accumulatedLeft + accumulatedRight)), Math.Max(0.0, arrangeSize.Height - (accumulatedTop + accumulatedBottom))); if (i < nonFillChildrenCount) { switch (DockPanel.GetDock(child)) { case Dock.Left: accumulatedLeft += childDesiredSize.Width; rcChild.Width = childDesiredSize.Width; break; case Dock.Right: accumulatedRight += childDesiredSize.Width; rcChild.X = Math.Max(0.0, arrangeSize.Width - accumulatedRight); rcChild.Width = childDesiredSize.Width; break; case Dock.Top: accumulatedTop += childDesiredSize.Height; rcChild.Height = childDesiredSize.Height; break; case Dock.Bottom: accumulatedBottom += childDesiredSize.Height; rcChild.Y = Math.Max(0.0, arrangeSize.Height - accumulatedBottom); rcChild.Height = childDesiredSize.Height; break; } } child.Arrange(rcChild); } return(arrangeSize); }
/// <summary>Arranges the content (child elements) of a <see cref="T:System.Windows.Controls.DockPanel" /> element.</summary> /// <param name="arrangeSize">The <see cref="T:System.Windows.Size" /> this element uses to arrange its child elements.</param> /// <returns>The <see cref="T:System.Windows.Size" /> that represents the arranged size of this <see cref="T:System.Windows.Controls.DockPanel" /> element.</returns> // Token: 0x06004A89 RID: 19081 RVA: 0x0015024C File Offset: 0x0014E44C protected override Size ArrangeOverride(Size arrangeSize) { UIElementCollection internalChildren = base.InternalChildren; int count = internalChildren.Count; int num = count - (this.LastChildFill ? 1 : 0); double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; double num5 = 0.0; for (int i = 0; i < count; i++) { UIElement uielement = internalChildren[i]; if (uielement != null) { Size desiredSize = uielement.DesiredSize; Rect finalRect = new Rect(num2, num3, Math.Max(0.0, arrangeSize.Width - (num2 + num4)), Math.Max(0.0, arrangeSize.Height - (num3 + num5))); if (i < num) { switch (DockPanel.GetDock(uielement)) { case Dock.Left: num2 += desiredSize.Width; finalRect.Width = desiredSize.Width; break; case Dock.Top: num3 += desiredSize.Height; finalRect.Height = desiredSize.Height; break; case Dock.Right: num4 += desiredSize.Width; finalRect.X = Math.Max(0.0, arrangeSize.Width - num4); finalRect.Width = desiredSize.Width; break; case Dock.Bottom: num5 += desiredSize.Height; finalRect.Y = Math.Max(0.0, arrangeSize.Height - num5); finalRect.Height = desiredSize.Height; break; } } uielement.Arrange(finalRect); } } return(arrangeSize); }
/// <summary>Measures the child elements of a <see cref="T:System.Windows.Controls.DockPanel" /> prior to arranging them during the <see cref="M:System.Windows.Controls.DockPanel.ArrangeOverride(System.Windows.Size)" /> pass.</summary> /// <param name="constraint">A maximum <see cref="T:System.Windows.Size" /> to not exceed.</param> /// <returns>A <see cref="T:System.Windows.Size" /> that represents the element size you want.</returns> // Token: 0x06004A88 RID: 19080 RVA: 0x00150124 File Offset: 0x0014E324 protected override Size MeasureOverride(Size constraint) { UIElementCollection internalChildren = base.InternalChildren; double num = 0.0; double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; int i = 0; int count = internalChildren.Count; while (i < count) { UIElement uielement = internalChildren[i]; if (uielement != null) { Size availableSize = new Size(Math.Max(0.0, constraint.Width - num3), Math.Max(0.0, constraint.Height - num4)); uielement.Measure(availableSize); Size desiredSize = uielement.DesiredSize; switch (DockPanel.GetDock(uielement)) { case Dock.Left: case Dock.Right: num2 = Math.Max(num2, num4 + desiredSize.Height); num3 += desiredSize.Width; break; case Dock.Top: case Dock.Bottom: num = Math.Max(num, num3 + desiredSize.Width); num4 += desiredSize.Height; break; } } i++; } num = Math.Max(num, num3); num2 = Math.Max(num2, num4); return(new Size(num, num2)); }