RelativeSource.TemplatedParent Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a static value that is used to return a RelativeSource constructed for the TemplatedParent mode.
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
A static RelativeSource.
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.
<!--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>
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.
For XAML information, see RelativeSource MarkupExtension.
제품 | 버전 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET 피드백
.NET은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.