TabControl.SelectedContentTemplate Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the DataTemplate of the currently selected item.
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
The DataTemplate of the selected item.
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>
<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>
The following example binds the SelectedContentTemplate property to the ContentPresenter.ContentTemplate property by using the TemplateBinding Markup Extension.
<ContentPresenter Content="{TemplateBinding SelectedContent}"
ContentTemplate="{TemplateBinding SelectedContentTemplate}"
ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}" />
The TabControl updates this property to reference to the DataTemplate for the active TabItem when the tab selection changes. Set TabControl.ContentTemplate or the ContentTemplate property on a TabItem to specify the DataTemplate for a TabItem.
The ControlTemplate of the TabControl uses the ContentPresenter.ContentSource property to bind the ContentPresenter.ContentTemplate 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 the ContentPresenter.ContentSource property to "SelectedContent" or by using TemplateBinding Markup Extension.
<object property="{TemplateBinding SelectedContentTemplate}"/>
Identifier field | SelectedContentTemplateProperty |
Metadata properties set to true |
None |
Ürün | Sürümler |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET geri bildirimi
.NET, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: