Windows.UI.Xaml.Setter.Target
June 22, 2022 ยท View on GitHub
-description
Gets or sets the path of a property on a target element to apply the Value to.
-property-value
The path of a property on a target element to apply the Value to.
-remarks
The Setter.Target property can be used in either a Style or a VisualState, but in different ways.
- When used in a Style, the property that needs to be modified can be specified directly.
- When used in VisualState, the Target property must be given a TargetPropertyPath (dotted syntax with a target element and property explicitly specified).
-examples
This example shows how to use multiple Setter statements inside the VisualState.Setters property to apply discrete property value changes on various elements (without animations) when a VisualState is applied.
<Page>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="NarrowState">
<VisualState.Setters>
<Setter Target="myPanel.Orientation" Value="Vertical"/>
<Setter Target="myPanel.Width" Value="380"/>
<Setter Target="myTextBlock.MaxLines" Value="3"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel x:Name="myPanel" Orientation="Horizontal">
<TextBlock x:Name="myTextBlock" MaxLines="5" Style="{ThemeResource BodyTextBlockStyle}"/>
</StackPanel>
</Grid>
</Page>
To update a value of an attached property, place the attached property path inside parentheses. This example shows how to update the RelativePanel.AlignRightWithPanel value on an element with the name 'TitleTextBlock'.
<RelativePanel>
<TextBlock x:Name="TitleTextBlock" Text="Title"/>
</RelativePanel>
...
<Setter Target="TitleTextBlock.(RelativePanel.AlignRightWithPanel)" Value="True"/>