What are the various layout panels in WPF ?

Open 1 Answers 7 Views Education
What are the various layout panels in WPF ?

1 Answer


WPF comes with the following five built-in panels:

  • Canvas
  • DockPanel
  • Grid
  • StackPanel
  • WrapPanel
The purpose and use of these panels is different. Each panel has a different way to position and reposition child controls placed within that panel. The following articles in this series will summarise these panels and their usages.
Similar to any other WPF control, a Panel control may be represented in two ways. First, at design-time using XAML elements and attributes, and second, at run-time, using a WPF class and its properties.
The code snippet in Listing 2 creates a Grid panel at design-time using XAML.
  1. <Window x:Class="CanvasPanelSample.Window1"   
  2.    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  3.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  4.    Title="Window1" Height="300" Width="300"   
  5.    Name="RootWindow">   
  6.    <Grid Name="GridPanel" Background="Blue"   
  7.       Width="250" Height="200"   
  8.       VerticalAlignment="Top"   
  9.       HorizontalAlignment="Left"   
  10.       FlowDirection="LeftToRight"   
  11.    />   
  12. </Window>   
Listing 2 generates Figure 2.
layout panels in WPF
by (280k points)