SelectedContentTemplateSelector Property

TabControl.SelectedContentTemplateSelector Property

Gets the DataTemplateSelector of the currently selected item. 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 DataTemplateSelector SelectedContentTemplateSelector { get; internal set; }
<object property="{TemplateBinding SelectedContentTemplateSelector}"/>

Property Value

Type: System.Windows.Controls.DataTemplateSelector
The DataTemplateSelector of the currently selected item. The default is null.

Identifier field

SelectedContentTemplateSelectorProperty

Metadata properties set to true

None

The TabControl updates this property to reference to the DataTemplateSelector for the active TabItem when the tab selection changes. Set TabControl.ContentTemplateSelector or the ContentTemplateSelector property on a TabItem to specify the DataTemplateSelector for a TabItem.

The ControlTemplate of the TabControl uses the ContentPresenter.ContentSource property to bind the ContentPresenter.ContentTemplateSelector property to this property. If you create a new ControlTemplate for the TabControl, be sure to the bind the ContentPresenter.Content property to this property by setting ContentPresenter.ContentSource property to "SelectedContent" or by using the TemplateBinding Markup Extension.

The following example creates a ControlTemplate for the TabControl. Setting the ContentSource property to "SelectedContent" creates aliases to the SelectedContent, SelectedContentTemplate, and SelectedContentTemplateSelector properties.

<Style  TargetType="{x:Type TabControl}">
  <Setter Property="OverridesDefaultStyle" Value="True" />
  <Setter Property="SnapsToDevicePixels" Value="True" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type TabControl}">
        <Grid KeyboardNavigation.TabNavigation="Local">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <TabPanel 
            Name="HeaderPanel"
            Grid.Row="0"
            Panel.ZIndex="1" 
            Margin="0,0,4,-1" 
            IsItemsHost="True"
            KeyboardNavigation.TabIndex="1"
            Background="Transparent" />
          <Border 
            Name="Border" 
            Grid.Row="1" 
            Background="{StaticResource WindowBackgroundBrush}" 
            BorderBrush="{StaticResource SolidBorderBrush}" 
            BorderThickness="1" 
            CornerRadius="2" 
            KeyboardNavigation.TabNavigation="Local"
            KeyboardNavigation.DirectionalNavigation="Contained"
            KeyboardNavigation.TabIndex="2" >
            <ContentPresenter 
              Name="PART_SelectedContentHost"
              Margin="4"
              ContentSource="SelectedContent" />
          </Border>
        </Grid>
        <ControlTemplate.Triggers>
          <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

The following example binds the SelectedContentTemplateSelector property to the ContentPresenter.ContentTemplateSelector property by using the TemplateBinding Markup Extension.

<ContentPresenter Content="{TemplateBinding SelectedContent}" 
     ContentTemplate="{TemplateBinding SelectedContentTemplate}" 
     ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}" />

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

Community Additions

ADD
Show:
© 2016 Microsoft