Bagikan melalui


RelativeSource.TemplatedParent Properti

Definisi

Mendapatkan nilai statis yang digunakan untuk mengembalikan yang RelativeSource dibangun untuk mode tersebut TemplatedParent .

public:
 static property System::Windows::Data::RelativeSource ^ TemplatedParent { System::Windows::Data::RelativeSource ^ get(); };
public static System.Windows.Data.RelativeSource TemplatedParent { get; }
static member TemplatedParent : System.Windows.Data.RelativeSource
Public Shared ReadOnly Property TemplatedParent As RelativeSource

Nilai Properti

Statis RelativeSource.

Contoh

Contoh berikut menunjukkan Style definisi kontrol kustom yang disebut NumericUpDown. Properti Text terikat TextBlock ke Value objek yang merupakan TemplatedParent, yang merupakan NumericUpDown kontrol tempat ini Style diterapkan dalam kasus ini.

<!--ControlTemplate for NumericUpDown that inherits from
    Control.-->
<Style TargetType="{x:Type local:NumericUpDown}">
  <Setter Property="HorizontalAlignment" Value="Center"/>
  <Setter Property="VerticalAlignment" Value="Center"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type local:NumericUpDown}">
        <Grid Margin="3">
          <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>

          <Border BorderThickness="1" BorderBrush="Gray" 
                  Margin="2" Grid.RowSpan="2" 
                  VerticalAlignment="Center" HorizontalAlignment="Stretch">
                  
            <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}" 
                       Width="60" TextAlignment="Right" Padding="5"/>
          </Border>
          
          <RepeatButton Command="{x:Static local:NumericUpDown.IncreaseCommand}"  
                        Grid.Column="1" Grid.Row="0">Up</RepeatButton>
                        
          <RepeatButton Command="{x:Static local:NumericUpDown.DecreaseCommand}"
                        Grid.Column="1" Grid.Row="1">Down</RepeatButton>

        </Grid>

      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

Keterangan

Tiga dari empat RelativeSourceMode nilai, PreviousData, , Selfatau TemplatedParent, dapat menghasilkan RelativeSource yang sepenuhnya statis, tidak berisi nilai privat yang unik. Semua penggunaan properti statis dapat berbagi objek yang sama, menghilangkan kebutuhan untuk mengalokasikan objek terpisah untuk setiap penggunaan. Oleh karena itu, menggunakan properti statis mengurangi penggunaan memori.

Penggunaan Teks XAML

Untuk informasi XAML, lihat RelativeSource MarkupExtension.

Berlaku untuk

Lihat juga