WPF Standard Control Demo App › DockPanel

DockPanel Layout

DockPanel arranges child elements by docking them to the edges (Top, Bottom, Left, Right) of the panel. The last child fills the remaining space by default. It is commonly used for application main window layouts.

Overview

The WPF DockPanel is a layout container designed for edge-anchoring patterns. Each child specifies a DockPanel.Dock attached property value โ€” Top, Bottom, Left, or Right โ€” and the panel progressively allocates space from that edge inward. Children are processed in XAML order: the first child claims its docked edge from the full available space, the second child claims from the remaining space, and so on. This stacking behaviour makes DockPanel extremely intuitive for building structured shells.

The most important behavioural property is LastChildFill. When True (the default), the last child in the panel fills whatever space remains after all preceding children have been docked. This is the classic "content area" pattern: dock a menu to the top, a status bar to the bottom, a navigation sidebar to the left, and let the last child โ€” typically a Frame, ScrollViewer, or Grid โ€” fill the central content area automatically.

DockPanel is deliberately simple and does not support row/column spanning, proportional sizing, or auto-fitting in the way Grid does. Its strength is clarity: the XAML ordering of children directly communicates the visual structure, making it easy to read and maintain. For the main window chrome of a desktop application โ€” toolbar, sidebar, status bar, content area โ€” DockPanel is often the most readable choice.

The Panel.ZIndex attached property works on DockPanel children just as on any other panel, allowing overlapping elements to stack visually without changing their layout positions. Background fills the entire panel area including any space not covered by children, which matters when LastChildFill is False and there is unclaimed central space.

Screen Preview

dockpanel demo screen

Demonstrated Properties

The following properties are demonstrated interactively in the WPF Standard Control Demo App. Each property can be configured in real time within the app to observe its behavior.

Property Values Description
LastChildFill bool Use the default True for the classic application shell pattern: dock peripheral controls (menu, toolbar, status bar, sidebar) first, then let the last child โ€” typically a Frame, ScrollViewer, or Grid โ€” automatically fill whatever space remains. Set to False when all children should be docked to specific edges and the centre may intentionally remain empty (e.g., a floating toolbar row). Pitfall: when LastChildFill="True", the DockPanel completely ignores the DockPanel.Dock setting on the last child and forces it to fill the remaining area. Setting a Dock value on the last element has no effect and can be misleading โ€” remove the Dock attribute from the last child to avoid confusion.
DockPanel.Dock (attached) Left / Top / Right / Bottom Use this on each child to pin it to a specific edge โ€” for example, Top for a menu bar, Bottom for a status bar, and Left for a navigation tree. Multiple children can be docked to the same edge; they stack outward-to-inward in XAML order. Pitfall: the order in which children appear in XAML directly determines how much space each one receives. A child docked earlier claims from the full available area; later children claim from what remains. Always write small UI components (menu, toolbar) before large ones (sidebar, content area). Docking a large element first leaves little room for elements that follow.
Background Brush Use this to paint the panel background and to control hit-testing. When LastChildFill="False", the background is visible in the unclaimed centre area. Pitfall: a null background (the default) disables hit-testing on the panel itself โ€” mouse events in uncovered areas pass straight through. Set Background="Transparent" to capture clicks without painting a colour.
Panel.ZIndex (attached) int Controls the render order of overlapping children. Higher values render on top. Although DockPanel children do not overlap in a typical layout, setting a high ZIndex on a floating panel or overlay child ensures it renders above all other content. Pitfall: ZIndex is scoped to siblings within the same DockPanel only โ€” it cannot make a child appear above elements in a different panel.

XAML Example

The following XAML shows a typical main window chrome layout using DockPanel:

<DockPanel LastChildFill="True">

  <!-- Top menu bar -->
  <Menu DockPanel.Dock="Top">
    <MenuItem Header="_File">
      <MenuItem Header="_New" />
      <MenuItem Header="_Open" />
    </MenuItem>
  </Menu>

  <!-- Top toolbar -->
  <ToolBar DockPanel.Dock="Top">
    <Button Content="New" />
    <Button Content="Save" />
  </ToolBar>

  <!-- Bottom status bar -->
  <StatusBar DockPanel.Dock="Bottom">
    <StatusBarItem Content="Ready" />
  </StatusBar>

  <!-- Left navigation panel -->
  <Border DockPanel.Dock="Left" Width="200"
          Background="#F0F0F0" Padding="8">
    <TextBlock Text="Navigation" />
  </Border>

  <!-- Centre content area (LastChildFill) -->
  <ScrollViewer>
    <TextBlock Text="Main content goes here." Margin="16" />
  </ScrollViewer>

</DockPanel>

Common Use Cases

Tips and Best Practices

Related Controls

Source Code

The source code for this demo screen is available on GitHub. Use the built-in code view buttons in the app to see the exact XAML for each property.

View DockPanel source code on GitHub →