concept ContentControl in category silverlight

This is an excerpt from Manning's book Silverlight 5 in Action.
It’s rare that you’ll create new controls that derive directly from UIElement or FrameworkElement. Instead, you’ll usually derive from Control or one of its descendants, such as ContentControl. ContentControl provides functionality above and beyond Control by enabling the containment and templating of arbitrary content.
The ContentPresenter is a descendant FrameworkElement that exists primarily to support the display of content in a ContentControl. Rather than having to put a TextBlock, Image, or other strongly typed content presentation element into your control template, you can use a ContentPresenter to bind to and display the content from the Content property. Table 12.7 shows the properties of the ContentPresenter element.
Table 12.7. Properties for the ContentPresenter element
Member
Description
Content The value assigned from the same property of a ContentControl ContentTemplate The template value assigned from the same property of a ContentControl Without the ContentPresenter, the ContentControl can’t do much of anything exciting. The ContentPresenter holds the logic to try to render the object passed into it. In fact, in a typical control template, the ContentPresenter is assigned values from the ContentControl via template binding, as shown here:
<ContentPresenter Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />I’ll cover TemplateBinding in chapter 14 when you’ll be working with control templates. For now, understand that TemplateBinding is used to bind an element in XAML to a dependency property in the control’s implementation. The Content property of the ContentPresenter in the preceding code is bound to the Content property of the containing ContentControl.
Together, Controls, ContentControls, and the associated ContentPresenter make up the core of the control tree in Silverlight. Another type of control, Items-Control, is equally as important. But before I show you the various types of ItemsControls, let’s look at some concrete implementations of ContentControls—specifically, those based on Button.
This ListBox uses the Items property to load options at design time. You also have the option of binding to a data source to make this list of items more dynamic. Binding to a data source will be covered in the next chapter. Regardless of whether you’re binding to a data source or defining items at design time, each item in the control is a ListBoxItem. A ListBoxItem is a type of ContentControl so you can use any visual tree you want for an item, as shown in listing 12.7.
In older technologies, the content of a control was usually very specific: a button could hold a text string in a caption property; an ImageButton could hold an image and text split across two properties; and so forth. Silverlight and WPF demanded a more flexible content model where a control could indicate that it supports the inclusion of arbitrary content rather than a specific atomic item of known type. From this requirement, the ContentControl was born.
ContentControl is a descendant of Control. As such, it inherits all of the properties, methods, and behaviors Control provides. It also adds the key concept of Content. Table 12.5 shows the two content-related properties that ContentControl adds to the Control type.
Table 12.5. Properties for the ContentControl abstract type
Member
Description
Content Assign the content (anything that can be rendered) to this property. If the content isn’t a UIElement and there’s no ContentTemplate or implicit data template associated with the type, Silverlight will call the object’s ToString method to display it. ContentTemplate This is a data template used to display the content assigned via the Content property. You’ll learn more about data templates in chapter 16 when I discuss binding. The Content for a ContentControl can be any arbitrary object. But if the type isn’t something that can be natively added to the visual tree (a UIElement) and there’s no explicit or implicit template, Silverlight will call the object’s ToString method to display it. This allows you to add any other Silverlight visual elements or a string value without having to do any additional work. If you’ve wondered why a button can have a simple string or a complex tree of elements as the content property, this is why.

This is an excerpt from Manning's book Silverlight 4 in Action: Silverlight 4, MVVM, and WCF RIA Services.
In older technologies, the content of a control was usually very specific: a button could hold a text string in a caption property; an ImageButton could hold an image and text split across two properties; and so forth. Silverlight and WPF demanded a more flexible content model where a control could indicate that it supports the inclusion of arbitrary content rather than a specific atomic item of known type. From this requirement, the ContentControl was born.
ContentControl is a descendent of Control. As such, it inherits all of the properties, methods, and behaviors Control provides. It also adds the key concept of Content. Table 10.5 shows the two content-related properties that ContentControl adds to the Control type.
Table 10.5. Properties for the ContentControl abstract type
Member
Description
Content Assign the content (anything that can be rendered) to this property. If the content isn’t a UIElement and there’s no ContentTemplate, Silverlight will call the object’s ToString method to display it. ContentTemplate This is a data template used to display the content assigned via the Content property. We’ll cover more on data templates in chapter 11 when we discuss binding. The Content for a ContentControl can be any arbitrary object. But, if the type isn’t something that can be natively added to the visual tree (a UIElement), Silverlight will call the object’s ToString method to display it. This allows you to add any other Silverlight visual elements or a string value without having to do any additional work. If you’ve wondered why a button can have a simple string or a complex tree of elements as the content property, this is why.
A ContentControl is a type of control defined by a single piece of content, which we discussed in chapter 10. Every ContentControl exposes a property called ContentTemplate, which specifies the DataTemplate to use when displaying the content of a ContentControl. This content can be styled with a DataTemplate using an approach similar to that shown in listing 11.9.