ContentControl Class
Updated: February 2009
Represents a control with a single piece of content.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
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"/>
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
System.Windows.Controls.ContentControl
System.Windows.Controls.Frame
System.Windows.Controls.GroupItem
System.Windows.Controls.HeaderedContentControl
System.Windows.Controls.Label
System.Windows.Controls.ListBoxItem
System.Windows.Controls.Primitives.ButtonBase
System.Windows.Controls.Primitives.StatusBarItem
System.Windows.Controls.ScrollViewer
System.Windows.Controls.ToolTip
System.Windows.Controls.UserControl
System.Windows.Window
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
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. |