.NET Framework Class Library
ContentControl Class

Updated: July 2008

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/xaml/presentation

Visual Basic (Declaration)
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
<ContentPropertyAttribute("Content")> _
Public Class ContentControl _
    Inherits Control _
    Implements IAddChild
Visual Basic (Usage)
Dim instance As ContentControl
C#
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
[ContentPropertyAttribute("Content")]
public class ContentControl : Control, 
    IAddChild
Visual C++
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)]
[ContentPropertyAttribute(L"Content")]
public ref class ContentControl : public Control, 
    IAddChild
J#
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable) */
/** @attribute ContentPropertyAttribute("Content") */
public class ContentControl extends Control implements IAddChild
JScript
public class ContentControl extends Control implements IAddChild
XAML Object Element Usage
<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.

The following example shows how to make a style for a ContentControl so that the control has an enhanced visual appearance.

C#
<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 Vista

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

July 2008

Added new members: ContentStringFormat property, OnContentStringFormatChanged method, ContentStringFormatProperty field.

SP1 feature change.

Page view tracker