Appendix C. Layout Controls

This appendix summarizes controls that are designed to arrange and contain other controls. They help you position the controls that make up the user interface.

The following sections very briefly summarize these controls. They list the controls' most important properties and provide simple XAML examples. For more detail, see Chapter 6.

Many of the controls define attached properties for use by child controls to tell the layout control how to position the children. Tables in this appendix summarize the key attached properties.

Because these controls are designed to hold other controls, they make logical places to define styles. For example, to make all of the Labels inside a Grid use the same font styles, you can add an unnamed Label style to the Grid's Resources section.

Canvas

The Canvas is a very simple layout control that lets you arrange its contents by explicitly setting the distances between their edges and those of the Canvas. See Table C-1 for the key properties.

Table C.1. Key Properties of Canvas

Property

Purpose

Background

The color used to fill the control's interior

ClipToBounds

Determines whether the control clips its children to its boundaries.

A child control can use attached properties to tell the Canvas how to position the child. The key attached properties for Canvas are given in Table C-2.

Table C.2. Key Attached Properties of Canvas

Property

Purpose

Canvas.Bottom

Sets the distance between the child's bottom edge and the Canvas's bottom edge.

Canvas.Left ...

Get WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.