Export (0) Print
Expand All

Panel.InternalChildren Property

Gets a UIElementCollection of child elements.

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

protected internal UIElementCollection InternalChildren { get; }

Property Value

Type: System.Windows.Controls.UIElementCollection
An ordered collection of UIElement objects. This property has no default value.

The returned collection includes items that are added directly in code, and also items that are generated by data binding.

Classes that are derived from Panel should use this property, instead of the Children property, for internal overrides such as MeasureCore and ArrangeCore.

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 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
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Show:
© 2014 Microsoft