Prev | Current Page 134 | Next

Matthew MacDonald

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

Content property. The
XAML parser uses the supplied text to set these properties.
The TextBox.Text property only allows strings. However, Button.Content is much more
interesting. As you??™ll learn in Chapter 5, the Content property accepts any element. For example,
here??™s a button that contains a shape object:

Because the Text and Content properties don??™t use collections, you can??™t include more
than one piece of content. For example, if you attempt to nest multiple elements inside a
CHAPTER 2 n XAML 41
Button, the XAML parser will throw an exception. The parser also throws an exception if you
supply nontext content (such as a Rectangle).
nNote As a general rule of thumb, all controls that derive from ContentControl allow a single nested element.
All controls that derive from ItemsControl allow a collection of items that map to some part of the
control (such as a list of items or a tree of nodes). All controls that derive from Panel are containers that are
used to organize groups of controls. The ContentControl, ItemsControl, and Panel base classes all use the
ContentProperty attribute.
Special Characters andWhitespace
XAML is bound by the rules of XML. For example, XML pays special attention to a few specific
characters, such as & and < and >.


Pages:
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146