RelativeSource.TemplatedParent Property

Gets a static value that is used to return a RelativeSource constructed for the TemplatedParent mode.

Namespace: System.Windows.Data
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public static RelativeSource TemplatedParent { get; }
/** @property */
public static RelativeSource get_TemplatedParent ()

public static function get TemplatedParent () : RelativeSource

 For XAML information, see RelativeSource MarkupExtension. 

Property Value

A static RelativeSource.

Three of the four RelativeSourceMode values, PreviousData, Self, or TemplatedParent, can produce a RelativeSource that is wholly static, containing no unique private values. All uses of the static property can share the same object, eliminating the need to allocate separate objects for each use. Therefore, using the static property reduces memory usage.

The following example shows the Style definition of a custom control called NumericUpDown. The Text property of the TextBlock is bound to the Value of the object that is the TemplatedParent, which is the NumericUpDown control that this Style is applied to in this case.

<Style TargetType="{x:Type local:NumericUpDown}">
  <Setter Property="HorizontalAlignment" Value="Center"/>
  <Setter Property="VerticalAlignment" Value="Center"/>
  <Setter Property="Template">
      <ControlTemplate TargetType="{x:Type local:NumericUpDown}">
        <Grid Margin="3">

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



For the complete sample, see NumericUpDown Custom Control with Theme and UI Automation Support Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0