#384 – The Benefits of Flow-Based Layout

WPF provides several benefits by making flow-based layout a default.

Resolution Independence

This is not really a benefit of flow-based layout, but a benefit based on the fact that WPF specifies positions and sizes in device independent units, rather than in pixels.  If the current DPI setting matches the native DPI of the device, then the actual size of the GUI elements will be as requested.

Controls Automatically Resized or Repositioned

Flow-based layout containers automatically reposition/resize child controls as the container is resized.

Controls Size to Fit Their Content

In WPF, you typically allow a control to size to fit it’s content.  This removes the need for tweaking size and position of elements if the content changes.

        <Button Content="Bob" HorizontalAlignment="Center"/>
        <Button Content="John Jacob Jingleheimer Smith" HorizontalAlignment="Center"/>

Easier Localization

When controls size to fit their content, you don’t need to tweak layout for each localized language.


#6 – WPF Layout

WPF uses a flow-based layout model for positioning controls, rather than a coordinate-based model where the location of each control is specified using exact pixel coordinates.  This is a layout model that is similar to how web pages are laid out using CSS.

The flow-based layout model allows WPF controls to be adjusted to fit the window that they are being rendered in.  A WPF GUI is therefore both size- and resolution-independent.

All WPF controls are hosted in a container.  The main flow-based containers are:

  • DockPanel
  • Grid
  • StackPanel
  • WrapPanel