Prev | Current Page 127 | Next

Matthew MacDonald

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

NET type).
Throughout this book, you??™ll see many examples of markup extensions at work, particularly
with resources and data binding.
Attached Properties
Along with ordinary properties, XAML also includes the concept of attached properties??”
properties that may apply to several controls but are defined in a different class. In WPF,
attached properties are frequently used to control layout.
Here??™s how it works. Every control has its own set of intrinsic properties. (For example, a
text box has a specific font, text color, and text content as dictated by properties such as Font-
Family, Foreground, and Text.) When you place a control inside a container it gains additional
features, depending on the type of container. (For example, if you place a text box inside a
CHAPTER 2 n XAML 37
grid, you need to be able to choose the grid cell where it??™s positioned.) These additional details
are set using attached properties.
Attached properties always use a two-part name in this form: DefiningType.Property-
Name. This two-part naming syntax allows the XAML parser to distinguish between a normal
property and an attached property.
In the eight ball example, attached properties allow the individual controls to place themselves
on separate rows in the (invisible) grid:

[Place question here.


Pages:
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139