This documentation is archived and is not being maintained.

Panel Class

Provides a base class for all Panel elements. Use Panel elements to position and arrange child objects in Windows Presentation Foundation (WPF) applications.

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

<LocalizabilityAttribute(LocalizationCategory.Ignore)> _
<ContentPropertyAttribute("Children")> _
Public MustInherit Class Panel _
	Inherits FrameworkElement _
	Implements IAddChild
Dim instance As Panel
This class is abstract; see Inheritance Hierarchy for derived non-abstract classes usable in XAML.

Content Model: Panel enforces a strong content model for child content. The Children collection of a Panel element can only consist of UIElement objects. Adding a UIElement child to a Panel implicitly adds it to the UIElementCollection for the Panel element.

WPF provides a comprehensive suite of derived Panel implementations, enabling many complex layouts. If you want to implement new layout containers, use the MeasureOverride and ArrangeOverride methods. For a demonstration of how to use these methods, see Create a Custom Content-Wrapping Panel Sample.

Panel elements do not receive mouse or stylus events if a Background is not defined. If you need to handle mouse or stylus events but do not want a background for your Panel, use Transparent.

Panel elements do not receive focus by default. To compel a panel element to receive focus, set the Focusable property to true.

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 New Size()

        For Each child As UIElement In InternalChildren
            panelDesiredSize = child.DesiredSize

        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))
        Return finalSize
    End Function 
End Class

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


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0