Delen via


Setter.Target Property

Definition

Gets or sets the path of a property on a target element to apply the Value to.

public:
 property TargetPropertyPath ^ Target { TargetPropertyPath ^ get(); void set(TargetPropertyPath ^ value); };
TargetPropertyPath Target();

void Target(TargetPropertyPath value);
public TargetPropertyPath Target { get; set; }
var targetPropertyPath = setter.target;
setter.target = targetPropertyPath;
Public Property Target As TargetPropertyPath

Property Value

The path of a property on a target element to apply the Value to.

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

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).

Applies to