Chapter 4. Common Properties

All of the WPF control classes inherit from the Control class, and that common ancestry gives them many properties in common. For example, most of them have properties that determine their size and position, foreground and background colors, transformations, and font properties.

This chapter describes some of the properties that many controls share. Later chapters mention some of these properties again where they are particularly relevant, but if you learn about them now, you will already know a lot about the controls described in the following chapters.

The following section describes a particularly important and confusing topic: sizing and positioning properties. Every WPF developer must understand these properties to arrange controls effectively.

Size and Position

Sizing and positioning properties can be very confusing because a control's geometry depends on several different properties, the way in which those properties interact, and even the control's container. For example, the same Button looks very different when it is placed inside a Grid, a StackPanel, or a Canvas.

The following section describes the most important properties for determining a control's size and position — its alignment properties. The next section then describes some simpler properties that also influence a control's size and position.

Alignment

Four of the most important properties that determine a control's size are Width, Height, HorizontalAlignment, and VerticalAlignment.

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.