This documentation is archived and is not being maintained.

ContentPresenter.ContentSource Property

Updated: January 2010

Gets or sets the base name to use during automatic aliasing. This is a dependency property.

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

public string ContentSource { get; set; }
<object ContentSource="string" .../>

Property Value

Type: System.String
The base name to use during automatic aliasing. The default is "Content".

Identifier field

ContentSourceProperty

Metadata properties set to true

None

This property should only be used when the ContentPresenter is in a template. When a template contains a ContentPresenter with ContentSource="Abc", the Content, ContentTemplate, and ContentTemplateSelector properties of the ContentPresenter are automatically aliased to Abc, AbcTemplate, and AbcTemplateSelector, respectively. Beginning with the .NET Framework version 3.5 Service Pack 1, setting ContentSource to "Abc" also causes the ContentStringFormat property to be aliased to AbcStringFormat.

The two most useful values for this property are "Content" and "Header".

The following example shows a style for a HeaderedContentControl that demonstrates the usage of the ContentSource property:

<Style TargetType="HeaderedContentControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
        <StackPanel>
          <Grid>
            <Rectangle Stroke="{TemplateBinding Background}"/>
            <ContentPresenter ContentSource="Header"/>
          </Grid>
          <Grid>
            <Rectangle Fill="{TemplateBinding Background}"/>
            <ContentPresenter ContentSource="Content"/>
          </Grid>
        </StackPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

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

January 2010

Fixed incorrect remarks.

Content bug fix.

July 2008

Revised remarks to reflect interaction with the ContentStringFormat property, which is new in SP1.

SP1 feature change.

Show: