TabControl.SelectedContentTemplate 属性

定义

获取当前所选项的 DataTemplate

public:
 property System::Windows::DataTemplate ^ SelectedContentTemplate { System::Windows::DataTemplate ^ get(); };
public System.Windows.DataTemplate SelectedContentTemplate { get; }
member this.SelectedContentTemplate : System.Windows.DataTemplate
Public ReadOnly Property SelectedContentTemplate As DataTemplate

属性值

选定项的 DataTemplate

示例

以下示例为 TabControl创建 ControlTemplate 。 将 ContentSource 属性设置为 "SelectedContent" 将创建 、 SelectedContentTemplateSelectedContentTemplateSelector 属性的SelectedContent别名。

<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>
          <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
              <VisualState x:Name="Disabled">
                <Storyboard>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                Storyboard.TargetProperty="(Border.BorderBrush).
                    (SolidColorBrush.Color)">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="#FFAAAAAA" />
                  </ColorAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
            </VisualStateGroup>
          </VisualStateManager.VisualStateGroups>
          <TabPanel x:Name="HeaderPanel"
                    Grid.Row="0"
                    Panel.ZIndex="1"
                    Margin="0,0,4,-1"
                    IsItemsHost="True"
                    KeyboardNavigation.TabIndex="1"
                    Background="Transparent" />
          <Border x:Name="Border"
                  Grid.Row="1"
                  BorderThickness="1"
                  CornerRadius="2"
                  KeyboardNavigation.TabNavigation="Local"
                  KeyboardNavigation.DirectionalNavigation="Contained"
                  KeyboardNavigation.TabIndex="2">
            <Border.Background>
              <LinearGradientBrush EndPoint="0.5,1"
                                   StartPoint="0.5,0">
                <GradientStop Color="{DynamicResource ContentAreaColorLight}"
                              Offset="0" />
                <GradientStop Color="{DynamicResource ContentAreaColorDark}"
                              Offset="1" />
              </LinearGradientBrush>
            </Border.Background>
            <Border.BorderBrush>
              <SolidColorBrush Color="{DynamicResource BorderMediumColor}"/>
            </Border.BorderBrush>
            <ContentPresenter x:Name="PART_SelectedContentHost"
                              Margin="4"
                              ContentSource="SelectedContent" />
          </Border>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

以下示例使用 TemplateBinding 标记扩展将 属性绑定到 SelectedContentTemplateContentPresenter.ContentTemplate 属性。

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

注解

当选项卡选择发生更改时, 将TabControl此属性更新为对活动 TabItem 的引用DataTemplate。 设置 TabControl.ContentTemplateContentTemplate 上的 TabItem 属性以指定 DataTemplateTabItem

ControlTemplateTabControl 使用 ContentPresenter.ContentSource 属性将 ContentPresenter.ContentTemplate 属性绑定到此属性。 如果为 TabControl创建新的 ,ControlTemplate请确保通过将 属性设置为ContentPresenter.ContentSource“SelectedContent”或使用 TemplateBinding 标记扩展将 属性绑定到ContentPresenter.Content此属性。

XAML 属性用法

<object property="{TemplateBinding SelectedContentTemplate}"/>  

依赖项属性信息

标识符字段 SelectedContentTemplateProperty
元数据属性设置为 true

适用于