Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

UIElement.Arrange Method

Positions child objects and determines a size for a UIElement. Parent objects that implement custom layout for their child elements should call this method from their layout override implementations to form a recursive layout update.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public void Arrange(
	Rect finalRect
)

Parameters

finalRect
Type: System.Windows.Rect
The final size that the parent computes for the child in layout, provided as a Rect value.

ExceptionCondition
InvalidOperationException

finalRect contained a Double.NaN or infinite value. See Remarks.

There is no reason to call Measure or Arrange outside of the context of overriding methods that perform custom layout actions. Silverlight layout works autonomously, based on detecting changes to the object tree and layout-relevant properties at run time. For more information, see Silverlight Layout System.

The finalRect you pass to Measure cannot have a Double.NaN value for any Rect value. Also, finalRect cannot have any infinite values for any Rect value.

Typically, calls to Arrange will incorporate a finalRect that uses the height and width values from DesiredSize for each element . Exceptions to this typical behavior might be necessary if an element holds a DesiredSize that the layout parent cannot accommodate, or if the sum total of all child element DesiredSize values cannot be accommodated or arranged. In such cases the child element content might be clipped, resized, or placed in a scroll region, which all depends on the specific functionality that is enabled in the layout parent container.

The following example shows how you would use Arrange within an ArrangeOverride implementation.


// Second arrange all children and return final size of panel
protected override Size ArrangeOverride(Size finalSize)
{
    // Get the collection of children
    UIElementCollection mychildren = Children;

    // Get total number of children
    int count = mychildren.Count;

    // Arrange children
    // We're only allowing 9 children in this panel.  More children will get a 0x0 layout slot.
    int i;
    for (i = 0; i < 9; i++)
    {

        // Get (left, top) origin point for the element in the 3x3 block
        Point cellOrigin = GetOrigin(i, 3, new Size(100, 100));

        // Arrange child
        // Get desired height and width. This will not be larger than 100x100 as set in MeasureOverride.
        double dw = mychildren[i].DesiredSize.Width;
        double dh = mychildren[i].DesiredSize.Height;

        mychildren[i].Arrange(new Rect(cellOrigin.X, cellOrigin.Y, dw, dh));

    }

    // Give the remaining children a 0x0 layout slot
    for (i = 9; i < count; i++)
    {
        mychildren[i].Arrange(new Rect(0, 0, 0, 0));
    }


    // Return final size of the panel
    return new Size(300, 300);
}

// Calculate point origin of the Block you are in
protected Point GetOrigin(int blockNum, int blocksPerRow, Size itemSize)
{
    // Get row number (zero-based)
    int row = (int)Math.Floor(blockNum / blocksPerRow);

    // Get column number (zero-based)
    int column = blockNum - blocksPerRow * row;

    // Calculate origin
    Point origin = new Point(itemSize.Width * column, itemSize.Height * row);
    return origin;

}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft