TabControl.SelectedContent Özellik

Tanım

Seçili TabItemdurumdaki öğesinin içeriğini alır.

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

Özellik Değeri

Seçili durumdaki TabItemöğesinin içeriği. Varsayılan değer: null.

Örnekler

Aşağıdaki örnek, şu anda seçili TabItemdurumda olan içindeki öğesini Person almak için özelliğini kullanırSelectedContent.

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

Aşağıdaki örnek için TabControlbir ControlTemplate oluşturur. ContentSource özelliğini "SelectedContent" olarak ayarlamak , SelectedContentTemplateve SelectedContentTemplateSelector özellikleri için SelectedContentdiğer adlar oluşturur.

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

Aşağıdaki örnek, TemplateBinding biçimlendirme uzantısınıContentPresenter.Content kullanarak özelliği özelliğine bağlarSelectedContent.

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

Açıklamalar

Bu özellik, sekme seçimi değiştiğinde Content etkin TabItem öğesine başvuracak şekilde güncelleştirilir.

ControlTemplate öğesinin özelliğiTabControl, özelliği bu özelliğe bağlamak ContentPresenter.Content için özelliğini kullanırContentPresenter.ContentSource. için TabControlyeni ControlTemplate bir oluşturursanız, özelliğini "SelectedContent" olarak ayarlayarak ContentPresenter.ContentSource veya TemplateBinding biçimlendirme uzantısını kullanarak özelliği bu özelliğe bağladığınızdan ContentPresenter.Content emin olun.

XAML Öznitelik Kullanımı

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

Bağımlılık Özelliği Bilgileri

Tanımlayıcı alanı SelectedContentProperty
Meta veri özellikleri olarak ayarlandı true Hiçbiri

Şunlara uygulanır