TabControl.SelectedContent 속성

정의

현재 선택된 TabItem의 콘텐츠를 가져옵니다.

public:
 property System::Object ^ SelectedContent { System::Object ^ get(); };
public object SelectedContent { get; }
member this.SelectedContent : obj
Public ReadOnly Property SelectedContent As Object

속성 값

Object

현재 선택된 TabItem의 콘텐츠입니다. 기본값은 null입니다.

예제

다음 예제에서는 합니다 SelectedContent 가져올 속성을 Person 현재 선택 된 TabItem합니다.

if (tabCtrl1.SelectedContent is Person)
{
    Person selectedPerson = tabCtrl1.SelectedContent as Person;
    StringBuilder personInfo = new StringBuilder();

    personInfo.Append(selectedPerson.FirstName);
    personInfo.Append(" ");
    personInfo.Append(selectedPerson.LastName);
    personInfo.Append(", ");
    personInfo.Append(selectedPerson.HomeTown);
    MessageBox.Show(personInfo.ToString());
}

If TypeOf tabCtrl1.SelectedContent Is Person Then

    Dim selectedPerson As Person = tabCtrl1.SelectedContent

    Dim personInfo As StringBuilder = New StringBuilder()

    personInfo.Append(selectedPerson.FirstName)
    personInfo.Append(" ")
    personInfo.Append(selectedPerson.LastName)
    personInfo.Append(", ")
    personInfo.Append(selectedPerson.HomeTown)
    MessageBox.Show(personInfo.ToString())
End If

다음 예제는 ControlTemplate 에 대 한는 TabControl합니다. 설정 합니다 ContentSource "SelectedContent" 속성에 대 한 별칭을 만듭니다 합니다 SelectedContent, SelectedContentTemplate, 및 SelectedContentTemplateSelector 속성입니다.

<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>

다음 예제에서는 합니다 SelectedContent 속성을를 ContentPresenter.Content 를 사용 하 여 속성을 TemplateBinding 태그 확장합니다.

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

설명

이 속성은 업데이트 참조 하는 Content 활성의 TabItem 탭 선택 영역이 변경 될 때입니다.

ControlTemplateTabControl 사용 하는 ContentPresenter.ContentSource 바인딩할 속성을 ContentPresenter.Content 속성을이 속성. 새로 만드는 경우 ControlTemplate 에 대 한는 TabControl, 바인드 해야는 ContentPresenter.Content 속성을 설정 하 여이 속성을 ContentPresenter.ContentSource "SelectedContent" 또는 사용 하 여 속성 TemplateBinding 태그 확장.

XAML 특성 사용

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

종속성 속성 정보

식별자 필드 SelectedContentProperty
메타 데이터 속성 설정 true 없음

적용 대상