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

次の例は、カスタム NumericUpDownコントロールのStyle定義を示しています。 のプロパティはText、この場合にValue適用されるコントロールStyleであるオブジェクトTemplatedParent``NumericUpDownのプロパティにバインドされます。TextBlock

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

注釈

4 つのRelativeSourceMode値 (またはTemplatedParent) のうち 3 つは、PreviousDataSelf一意のプライベート値を含まず、完全に静的な値を生成RelativeSourceできます。 静的プロパティの使用はすべて同じオブジェクトを共有できるため、使用ごとに個別のオブジェクトを割り当てる必要がなくなります。 したがって、静的プロパティを使用すると、メモリ使用量が削減されます。

XAML テキストの使用法

XAML の詳細については、「 RelativeSource MarkupExtension」を参照してください。

適用対象

こちらもご覧ください