Skip to main content
.NET Framework Class Library
FrameworkElementArrangeOverride Method

When overridden in a derived class, positions child elements and determines a size for a FrameworkElement derived class.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax
Protected Overridable Function ArrangeOverride ( _
	finalSize As [%$TOPIC/ms598098_en-us_VS_110_2_0_0_0_0%] _
) As [%$TOPIC/ms598098_en-us_VS_110_2_0_0_0_1%]
protected virtual [%$TOPIC/ms598098_en-us_VS_110_2_0_1_0_0%] ArrangeOverride(
	[%$TOPIC/ms598098_en-us_VS_110_2_0_1_0_1%] finalSize
)
protected:
virtual [%$TOPIC/ms598098_en-us_VS_110_2_0_2_0_0%] ArrangeOverride(
	[%$TOPIC/ms598098_en-us_VS_110_2_0_2_0_1%] finalSize
)
abstract ArrangeOverride : 
        finalSize:[%$TOPIC/ms598098_en-us_VS_110_2_0_3_0_0%] -> [%$TOPIC/ms598098_en-us_VS_110_2_0_3_0_1%]  
override ArrangeOverride : 
        finalSize:[%$TOPIC/ms598098_en-us_VS_110_2_0_3_0_2%] -> [%$TOPIC/ms598098_en-us_VS_110_2_0_3_0_3%]

Parameters

finalSize
Type: System.WindowsSize

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

Return Value

Type: System.WindowsSize
The actual size used.
Remarks

Notes to Inheritors

Control authors who want to customize the arrange pass of layout processing should override this method. The implementation pattern should call Arrange on each visible child element, and pass the final desired size for each child element as the finalRect parameter. Parent elements should call Arrange on each child, otherwise the child elements will not be rendered.

Many derived classes offer implementations of this method. Prominent ones include: WindowArrangeOverride, PageArrangeOverride and ControlArrangeOverride.

Examples

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
    Inherits Panel
    'Override the default Measure method of Panel. 

    Protected Overrides Function MeasureOverride(ByVal availableSize As System.Windows.Size) As System.Windows.Size
        Dim panelDesiredSize As Size = New Size()
        ' In our example, we just have one child.  
        ' Report that our panel requires just the size of its only child. 
        For Each child As UIElement In InternalChildren
            child.Measure(availableSize)
            panelDesiredSize = child.DesiredSize
        Next 
        Return panelDesiredSize
    End Function 
    Protected Overrides Function ArrangeOverride(ByVal finalSize As System.Windows.Size) As System.Windows.Size
        For Each child As UIElement In InternalChildren
            Dim x As Double = 50
            Dim y As Double = 50
            child.Arrange(New Rect(New System.Windows.Point(x, y), child.DesiredSize))
        Next 
        Return finalSize
    End Function 
End Class
public class PlotPanel : Panel
{
    // Default public constructor 
    public PlotPanel()
        : base()
    {
    }

    // Override the default Measure method of Panel 
    protected override Size MeasureOverride(Size availableSize)
    {
        Size panelDesiredSize = new Size();

        // In our example, we just have one child.  
        // Report that our panel requires just the size of its only child. 
        foreach (UIElement child in InternalChildren)
        {
            child.Measure(availableSize);
            panelDesiredSize = child.DesiredSize;
        }

        return panelDesiredSize ;
    }
    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
    }
}
public: 
      ref class PlotPanel : Panel {

      public: 
         PlotPanel () {};

      protected: 
         // Override the default Measure method of Panel 
         virtual Size MeasureOverride(Size availableSize) override
         {
             Size^ panelDesiredSize = gcnew Size();

             // In our example, we just have one child.  
             // Report that our panel requires just the size of its only child. 
             for each (UIElement^ child in InternalChildren)
             {
                 child->Measure(availableSize);
				 panelDesiredSize = child->DesiredSize;
             }
             return *panelDesiredSize ;
         }

      protected: 
         virtual System::Windows::Size ArrangeOverride (Size finalSize) override 
         {
            for each (UIElement^ child in InternalChildren)
            {
               double x = 50;
               double y = 50;
               child->Arrange(Rect(Point(x, y), child->DesiredSize));
            }
            return finalSize;
         };
      };
Version Information

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.