ContentControl Class

Updated: February 2009

Represents a control with a single piece of content.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

'Declaration
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
<ContentPropertyAttribute("Content")> _
Public Class ContentControl _
	Inherits Control _
	Implements IAddChild
'Usage
Dim instance As ContentControl
<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"/>

System.Object
  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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft