This documentation is archived and is not being maintained.

ContentPresenter Class

Updated: July 2008

Displays the content of a ContentControl.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
Public Class ContentPresenter _
	Inherits FrameworkElement
Dim instance As ContentPresenter
<ContentPresenter .../>

Typically, when you would use the ContentPresenter directly is within the ControlTemplate of a ContentControl to mark where the content is to be added.

Every ContentControl type has a ContentPresenter within its ControlTemplate. The ContentPresenter is responsible for the UI generation. For example, when you apply a DataTemplate to an ItemsControl such as a ListBox, behind the scenes it is actually the ContentPresenter within the ListBoxItem that creates the UI of each item. For more information about that particular example, see ItemTemplate.

The following shows a Button Style that sets the ControlTemplate of a Button. The ControlTemplate defines that the Button appears as an Ellipse within a Grid element. The ContentPresenter marks that the Content of the Button should be displayed and centered vertically and horizontally within the Grid.

<Style TargetType="Button">
  <!--Set to true to not get any properties from the themes.-->
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
      <ControlTemplate TargetType="Button">
          <Ellipse Fill="{TemplateBinding Background}"/>
          <ContentPresenter HorizontalAlignment="Center"

The following image shows the appearance of the Button when this gets applied:

Button ControlTemplate sample

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




July 2008

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

SP1 feature change.