Complex Properties
As handy as type converters are, they aren??™t practical for all scenarios. For example, some
properties are full-fledged objects with their own set of properties. Although it??™s possible to
create a string representation that the type converter could use, that syntax might be difficult
to use and prone to error.
Fortunately, XAML provides another option: property-element syntax. With propertyelement
syntax, you add a child element with a name in the form Parent.PropertyName. For
example, the Grid has a Background property that allows you to supply a brush that??™s used to
paint the area behind the controls. If you want to use a complex brush??”one more advanced
than a solid color fill??”you??™ll need to add a child tag named Grid.Background, as shown here:
CHAPTER 2 n XAML 34
...
...
The key detail that makes this work is the period (.) in the element name. This distinguishes
properties from other types of nested content.
This still leaves one detail??”namely, once you??™ve identified the complex property you
want to configure, how do you set it? Here??™s the trick. Inside the nested element, you can add
another tag to instantiate a specific class. In the eight ball example (shown in Figure 2-1), the
background is filled with a gradient.
Pages:
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134