Updated: February 2009
Represents a control with a single piece of content.
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _ <ContentPropertyAttribute("Content")> _ Public Class ContentControl _ Inherits Control _ Implements IAddChild
Dim instance As ContentControl
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)] [ContentPropertyAttribute("Content")] public class ContentControl : Control, IAddChild
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)] [ContentPropertyAttribute(L"Content")] public ref class ContentControl : public Control, IAddChild
public class ContentControl extends Control implements IAddChild
<ContentControl> Content </ContentControl>
A ContentControl has a limited default style. If you want to enhance the appearance of the control, you can create a new DataTemplate. For more information, see Data Templating Overview. Another typical scenario is to use the ContentControl to show more information about an item selected in an ItemsControl control. For more information, see How to: Bind to a Collection and Display Information Based on Selection.
Content Model: ContentControl is the class from which other content controls inherit. For more information on the content model for ContentControl, see Controls Content Model Overview.
Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.
The following example shows how to make a style for a ContentControl so that the control has an enhanced visual appearance.
<Style x:Key="ContentCtrl" TargetType="{x:Type ContentControl}"> <Setter Property="Background" Value="Red"/> <Setter Property="Foreground" Value="Green"/> <Setter Property="FontSize" Value="20"/> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ContentControl}"> <Grid> <!--Keep the Ellipse a circle when ContentControl.Width is set.--> <Ellipse Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" Fill="{TemplateBinding Background}"/> <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> ... <ContentControl Width="75" Style="{StaticResource ContentCtrl}" Content="Hello"/>
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
Date
History
Reason
February 2009
Described how default styles change dependency properties.
Customer feedback.
July 2008
Added new members: ContentStringFormat property, OnContentStringFormatChanged method, ContentStringFormatProperty field.
SP1 feature change.