RelativeSource.TemplatedParent 屬性

定義

取得靜態值,作用是傳回針對 RelativeSource 模式建構的 TemplatedParent

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

屬性值

RelativeSource

靜態 RelativeSource

範例

下列範例顯示 Style 稱為 NumericUpDown 的自訂控制項定義。 的 屬性會系結至 Value 物件之 的 TemplatedParent ,這是 NumericUpDown 在此案例中套用這個 的控制項 StyleTextBlock Text

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

備註

RelativeSourceMode 個值中的三個 RelativeSourcePreviousDataSelfTemplatedParent ,可以產生完全靜態的 ,不包含唯一的私人值。 靜態屬性的所有用法都可以共用相同的物件,而不需要為每個用途配置個別的物件。 因此,使用靜態屬性可減少記憶體使用量。

XAML 文字使用方式

如需 XAML 資訊,請參閱 RelativeSource MarkupExtension

適用於

另請參閱