O'Reilly logo

WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required