Prev | Current Page 217 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"


This markup is slightly longer, but it has the advantage of declaring the controls in the
order they appear, which makes it easier to understand. In this case, the approach you take is
simply a matter of preference. And if you want, you could replace the nested StackPanel with
a one-row, two-column Grid.
nNote You can create almost any interface using nested Grid containers. (One exception is wrapped rows
or columns that use the WrapPanel.) However, when you??™re dealing with small sections of user interface or
laying out a small number of elements, it??™s often simpler to use the more specialized StackPanel and
DockPanel containers.
Spanning Rows and Columns
You??™ve already seen how you place elements in cells using the Row and Column attached
properties. You can also use two more attached properties to make an element stretch over
several cells: RowSpan and ColumnSpan. These properties take the number of rows or
columns that the element should occupy.
For example, this button will take all the space that??™s available in the first and second cell
of the first row:

And this button will stretch over four cells in total by spanning two columns and two
rows: