TabControl.ContentTemplate Property

Gets or sets the DataTemplate to apply to any TabItem that does not have a ContentTemplate or ContentTemplateSelector property defined. 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 DataTemplate ContentTemplate { get; set; }
<object ContentTemplate="{ResourceExtension TemplateResourceKey}"/>

XAML Values

ResourceExtension

One of the following: StaticResource, or DynamicResource. See Resources Overview.

TemplateResourceKey

The key that identifies the template being requested. The key refers to an existing resource in a ResourceDictionary.

NoteNote:

Property element syntax is technically possible, but not recommended. See Inline Styles and Templates.

Property Value

Type: System.Windows.DataTemplate
The DataTemplate to apply to any TabItem that does not have a ContentTemplate or ContentTemplateSelector property defined. The default is null.

Identifier field

ContentTemplateProperty

Metadata properties set to true

None

The following example creates two DataTemplate objects. The DataTemplate called contentTemplate is assigned to the ContentTemplate of the TabControl and the DataTemplate called tabItemTemplate is assigned to the ContentTemplate of the second TabItem. All TabItem objects contain the white rectangle defined in contentTemplate, except the second TabItem, which has a gray rectangle, as defined in tabItemTemplate.

<DataTemplate x:Key="contentTemplate">
  <Grid>
    <Rectangle Fill="White"/>
    <ContentPresenter Content="{Binding}"/>
  </Grid>
</DataTemplate>

<DataTemplate x:Key="tabItemTemplate">
  <Grid>
    <Rectangle Fill="Gray"/>
    <ContentPresenter Content="{Binding}"/>
  </Grid>
</DataTemplate>


...


<TabControl Width="250" Height="300" 
            ContentTemplate="{StaticResource contentTemplate}">
  <TabItem Header="One">
    <Ellipse Width="200" Height="200" Fill="#CABCAB"/>
  </TabItem>
  <TabItem Header="Two"
           ContentTemplate="{StaticResource tabItemTemplate}">
    <Ellipse Width="200" Height="200" Fill="#BADDF00D"/>
  </TabItem>
  <TabItem Header="Three">
    <Ellipse Width="200" Height="200" Fill="#654321"/>
  </TabItem>
  <TabItem Header="Four">
    <Ellipse Width="200" Height="200" Fill="#123456"/>
  </TabItem>
  <TabItem Header="Five">
    <Ellipse Width="200" Height="200" Fill="#F11001"/>
  </TabItem>
</TabControl>

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft