Instead, you need to wrap it in a class that derives from UIElement, such as TextBlock
or Label.
If you want to create a truly exotic button, you could even place other content controls
such as text boxes and buttons inside (and still nest elements inside these). It??™s doubtful that
such an interface would make much sense, but it is possible. Figure 5-2 shows some sample
buttons.
Figure 5-2. Buttons with different types of nested content
CHAPTER 5 n CONTENT 122
This is the exact same content model you saw with windows. Just like the Button class, the
Window class allows a single nested element, which can be a piece of text, an arbitrary object,
or an element.
nNote One of the few elements that is not allowed inside a content control is the Window. When you create
a Window, it checks to see if it??™s the top-level container. If it??™s placed inside another element, the Window
throws an exception.
Aside from the Content property, the ContentControl class adds very little. It includes a
HasContent property that returns True if there is content in the control, and a ContentTemplate
that allows you to build a template telling the control how to display an otherwise
unrecognized object. Using ContentTemplate, you can display non-UIElement-derived
objects more intelligently. Instead of just calling ToString() to get a string, you can take various
property values and arrange them into more complex markup.
Pages:
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262