What is Layout in WPF ?

WPF has a Layout System that take care of element’s layout – how it is positioned, being sized and drawn. A Layout describes the arrangement of its Panel element’s child collection.

In WPF we are provided with some Panel elements, which we generally call them Layout Panels.




Layouts

  • Canvas
  • StackPanel
  • WrapPanel
  • DockPanel
  • Grid

SIDE NOTE :
These all above Panel elements are derived from an abstract class ‘Panel’ which enables us to achieve many complex layouts.

Take a look about each of the above mentioned Layouts.

Canvas Layout

This layout is used to position controls using X & Y coordinates.

The main properties are:

  • Canvas.Left
  • Canvas.Right
  • Canvas.Top
  • Canvas.Bottom

StackPanel Layout

The contents are placed one above the other vertically or one besides the other horizontally. The ‘Orientation’ property can be set to vertical or horizontal. The default value is Vertical.

WrapPanel Layout

This layout wraps the controls to the next line or next column. The ‘Orientation’ property can be set to vertical or horizontal. The default value is Horizontal.

DockPanel Layout

The controls are docked at the four corners in this layout.

The main property is ‘Dock’ which can be
– Left,
– Right,
– Top or
– Bottom

Grid Layout

Use this layout to position controls in specified rows and columns.

The main properties are:

  • Grid.Row
  • Grid.Column
  • Grid.RowSpan
  • Grid.ColumnSpan