Arranging Content with Panels

When you are building a GUI using WPF, you are required to make use of panel types. Recall that a
ContentControl can only have one item assigned to its Content property.

If you were to add a UI widget directly to a ContentControl, it will be positioned in the dead center. Consider
the following simple window, which sets a
Rectangle as content (note the lack of any panel type):


<Window x:Class = "FunWithPanels.Window1"
  xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
  Title = "The only content I have..." Height = "299" Width = "348">

<Rectangle Fill = "Black" Height = "50" Width = "100"/>

</Window>














Multiple UI elements must first be arranged in one of the provided panel types. Here are the most frequently
used panel types, all of which are defined in the
System.Windows.Controls namespace of
PresentationFoundation.dll.






























Be aware that each one of these panel types can be configured in numerous ways. Your lab time will illustrate
a number of configuration settings. However, you will most certainly want to look up panels of interest in the
.NET Framework SDK documentation for full details.
WPF Panels
Table of Contents
Copyright (c) 2008.  Intertech, Inc. All Rights Reserved.  This information is to be used exclusively as an
online learning aid.  Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials


WPF Panel Type


Meaning in Life


Canvas

Provides a ‘classic’ mode of content placement. Items stay exactly where
you put them at design time as items make use of absolute positions.


DockPanel

Locks content to a specified side of the panel (Top, Bottom, Left, or
Right).


Grid

Arranges content within a series of cells, based on rows and columns,
maintained within a tabular grid.


StackPanel

Stacks content in a vertical or horizontal manner as dictated by the
Orientation property.


WrapPanel

Positions content from left to right, breaking the content to the next line
at the edge of the containing box.

Subsequent ordering happens sequentially from top to bottom or from
right to left, depending on the value of the Orientation property.
Services