FrameworkElement.ArrangeOverride method

Expand
This topic has not yet been rated - Rate this topic

FrameworkElement.ArrangeOverride method

[This documentation is preliminary and is subject to change.]

Provides the behavior for the "Arrange" pass of layout. Classes can override this method to define their own "Arrange" pass behavior.

Syntax


protected virtual Size ArrangeOverride(
  Size finalSize
)

Parameters

finalSize

Type: Size

The final area within the parent that this object should use to arrange itself and its children.

Return value

Type: Size

The actual size that is used after the element is arranged in layout.

Examples

This example implements ArrangeOverride to customize the "Arrange" pass logic for a custom panel implementation. Note in particular these aspects of the code:

  • Iterates over children.

  • For each child, calls Arrange, using a Rect where Height and Width are based on DesiredSize, and X and Y are based on logic that is specific to the panel.

  • Returns its size (in this case, this simple panel returns a fixed size rather than a size calculated on accumulating the arranged Rect value measurements).


// 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);
}


Requirements

Minimum supported client

Windows 8 Release Preview

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

FrameworkElement

 

 

Build date: 5/22/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD