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 elements and determines a size for a UIElement. Parent elements call this method from their ArrangeCore implementation (or a WPF framework-level equivalent) to form a recursive layout update. This method constitutes the second pass of a layout update.

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

public void Arrange (
	Rect finalRect
)
public void Arrange (
	Rect finalRect
)
public function Arrange (
	finalRect : Rect
)
You cannot use methods in XAML.

Parameters

finalRect

The final size that the parent computes for the child element, provided as a Rect instance.

For WPF framework-level element deriving scenarios, behavior for Arrange should not (and cannot, unless you shadow) be changed. Instead, you should override the ArrangeOverride implementation in your class. Your ArrangeOverride implementation is called internally by Arrange as part of default WPF framework-level layout operations. Your ArrangeCore implementation should also call ArrangeOverride on each child element, if it has child elements.

For WPF core-level element deriving scenarios, the behavior for Arrange should not (and cannot, unless you shadow) be changed. Instead, you should override ArrangeCore in your class. Your ArrangeCore implementation is called internally by Arrange as part of default WPF framework-level layout operations. However, this assumes you are using WPF framework-level layout and its layout system, which is often not the case if you are specifically deriving elements at the WPF core-level from the UIElement base element class. Your ArrangeCore implementation should also call Arrange on each child element, if it has child elements. Note that the WPF core-level scenario implies that you are not using a FrameworkElement derived class, because FrameworkElement seals ArrangeCore.

Computation of WPF framework-level layout positioning in Windows Presentation Foundation (WPF) is comprised of a Measure call and an Arrange call. During the Measure call, an element determines its size requirements using a provided availableSize input. During the Arrange call, the element size is finalized and returned.

availableSize can be any number from zero to infinite. Elements to be laid out return the minimum Size they require through the availableSize parameter.

When a layout is first instantiated, it always receives a Measure call before Arrange. However, after the first layout pass, it may receive an Arrange call without a Measure; this can happen when a property that affects only Arrange is changed (such as alignment), or when the parent receives an Arrange without a Measure. A Measure call will automatically invalidate an Arrange call.

Layout updates generally occur asynchronously (at a time determined by the layout system). An element might not immediately reflect changes to properties that affect element sizing (such as Width).

NoteNote:

Layout updates can be forced by using the UpdateLayout method; however, calling this function is not recommended, as it is usually unnecessary and can cause poor performance. In many situations where calling UpdateLayout might be appropriate, the layout system will probably already be processing updates. The layout system can process layout changes in a manner that can optimize all necessary updates as part of a package.

The layout system keeps two separate queues of invalid layouts, one for Measure and one for Arrange. The layout queue is sorted based upon the order of elements in the visual tree. Elements higher in the tree are at the top of the queue, in order to avoid redundant layouts caused by repeated changes in parents. Duplicate entries are automatically removed from the queue, and elements are automatically removed from the queue if they are already valid.

When updating layout, the Measure queue is emptied first, followed by the Arrange queue. An element in the Arrange queue will never be arranged if there is an element in the Measure queue.

This example shows how to override the default layout behavior of the Panel element and create custom layout elements that are derived from Panel.

The example defines a simple custom Panel element called PlotPanel, which positions child elements according to two hard-coded x- and y-coordinates. In this example, x and y are both set to 50; therefore, all child elements are positioned at that location on the x and y axes.

To implement custom Panel behaviors, the example uses the MeasureOverride and ArrangeOverride methods. Each method returns the Size data that is necessary to position and render child elements.

public class PlotPanel : Panel
{
    // Default public constructor
    public PlotPanel()
        : base()
    {
    }

    // Override the default Measure method of Panel
    protected override Size MeasureOverride(Size availableSize)
    {
        Size childSize = availableSize;
        foreach (UIElement child in InternalChildren)
        {
            child.Measure(childSize);
        }
        return availableSize;
    }
    protected override Size ArrangeOverride(Size finalSize)
    {
        foreach (UIElement child in InternalChildren)
        {
            double x = 50;
            double y = 50;

            child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
        }
        return finalSize; // Returns the final Arranged size
    }
}

For the complete sample, see Create a Simple Custom Panel Behavior Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

Show:
© 2014 Microsoft. All rights reserved.