#22 – Layout Controls

In WPF, the primary model for control layout is flow-based, rather than coordinate-based.  Child controls are added to a layout container control, which manages the location and size of the child controls based on the size and shape of the container.

Here are the main layout controls included in WPF:

  • Canvas – Coordinate-based layout container
  • DockPanel – Controls aligned against one edge of container (e.g. Top/Bottom/Left/Right/Fill)
  • Grid – Controls positioned in rows and columns.  (Default top-level control in empty WPF app)
  • StackPanel – Controls in horizontal or vertical stack
  • UniformGrid – Controls positioned in a grid where all cells have the same size
  • VirtualizingStackPanel – Arrange controls in horizontal or vertical stack.  Controls shown are a visible subset from larger list of items.  Loads controls as needed, i.e. as they become visible.
  • WrapPanel – Controls placed on single line, left-to-right, then wrap to next line if needed.  Can also be top-to-bottom, wrap to next column.