This topic has not yet been rated - Rate this topic

DockPanel Class

[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Arranges child elements around the edges of the panel. Optionally, the last added child element can occupy the remaining space.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)
public class DockPanel : Panel
<controls:DockPanel .../>

XAML Values

controls:

A prefix that is defined to map the XML namespace for the System.Windows.Controls assembly and the System.Windows.Controls CLR namespace.

DockPanel is one of the Panel controls that enables layout. DockPanel is used when you want to arrange a set of objects around the edges of a panel. You specify where a child element is located in the DockPanel with the Dock property. If you set the LastChildFill property to true (the default value) and the last element is allowed to resize, the last element added to the panel will resize to fill the remaining space. If the last element is set to a specific size, the last element will be set to the specified size and positioned in the middle of the remaining space.

The order in which elements are added to the DockPanel is important. For example, if you add three child elements that have their Dock properties set to Left, they will stack from the left side of the control with the last element added the furthest right. If elements are added that exceed the space of the DockPanel, the last elements that are added that exceed the space of the panel will be truncated.

The following image shows a DockPanel control with the last child filling the middle of the control.

DockPanel control

The following table summarizes the other available layout containers provided by Silverlight.

Panel Name

Description

Canvas

Defines an area that you can explicitly position child elements.

Grid

Defines a flexible grid area consisting of columns and rows.

StackPanel

Arranges child elements into a single line that can be oriented horizontally or vertically.

WrapPanel

Positions child elements sequentially from left to right or top to bottom. When elements extend beyond the panel edge, elements are positioned in the next row or column.

The following example shows a DockPanel with child elements positioned at the edges of the panel and the last child filling the remaining space.

<Border BorderBrush="Black" BorderThickness="3" >
    <StackPanel x:Name="LayoutRoot" Background="White">
        <TextBlock Margin="5" Text="Dock Panel" />
        <Border BorderBrush="Black" BorderThickness="3" >
            <controls:DockPanel LastChildFill="true" Height="265">
                <Button  Content="Dock: Left" controls:DockPanel.Dock ="Left" />
                <Button Content="Dock: Right" controls:DockPanel.Dock ="Right" />
                <Button  Content="Dock: Top" controls:DockPanel.Dock ="Top" />
                <Button  Content="Dock: Bottom" controls:DockPanel.Dock ="Bottom" />
                <Button Content="Last Child" />
            </controls:DockPanel>
        </Border>
    </StackPanel>
</Border>


Run this 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.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)