Prev | Current Page 130 | Next

Matthew MacDonald

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


Nesting Elements
As you??™ve seen, XAML documents are arranged as a heavily nested tree of elements. In the current
example, a Window element contains a Grid element, which contains TextBox and Button
elements.
XAML allows each element to decide how it deals with nested elements. This interaction
is mediated through one of four mechanisms that are evaluated in this order:
??? If the parent implements IList, the parser calls IList.Add() and passes in the child.
??? If the parent implements IDictionary, the parser calls IDictionary.Add() and passes in
the child. When using a dictionary collection, you must also set the x:Key attribute to
give a key name to each item.
??? If the parent is decorated with the ContentProperty attribute, the parser uses the child
to set that property.
For example, earlier in this chapter you saw how a LinearGradientBrush can hold a
collection of GradientStop objects using syntax like this:







The XAML parser recognizes the LinearGradientBrush.GradientStops element is a complex
property because it includes a period.


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