,

Content Controls

Controls that are derived from ContentControl are able to host a single object. ContentControls include Buttons, ListBoxItems, and containers such as the PhoneApplicationFrame and the ScrollViewer control (see Figure 5.3).

Image

FIGURE 5.3 Content controls (excludes some mapping related types).

This chapter does not cover the Frame and its derived classes. For information on the Frame class see Chapter 3, “Understanding the Application Execution Model.” Nor does this chapter cover the PanoramaItem and PivotItem classes, which are discussed in Chapter 11.

ContentControl has a Content property, whose value can be of any type. The way content is presented in the UI, however, depends on its type and whether a DataTemplate is associated with the ContentControl. The following lists the three ways in which content is presented:

Image UIElementsIf the object derives from UIElement, the object will be rendered.

Image Non-UIElements—If the object does not derive from UIElement, its ToString method is used to retrieve a textual representation of the object. If the ToString method has not been overridden, the result is the fully qualified class name of the object.

Image Non-UIElements with an associated DataTemplate—The ContentControl.ContentTemplate allows you to specify a DataTemplate, either as a StaticResource or inline, which is used to display an object. Data binding expressions within the DataTemplate are used to extract the object’s property values and to render them.

To better understand the Content property, let’s look at a commonly used ContentControl: the Button control. With a Button, you can set its Content property to a string, as shown:

<Button Content="Tap me!" />

Unlike the TextBlock control, for example, the Button control does not have a Text property, yet by setting the Content property to a string, the Button displays the string.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.47.51