Setter.Target 屬性

定義

取得或設定要套用 Value 的目標專案上屬性的路徑。

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

屬性值

要套用 Value 的目標專案上的屬性路徑。

範例

此範例示範如何在 VisualState.Setters 屬性內使用多個 Setter 語句,在套用 VisualState 時套用不) 動畫的各種元素 (套用離散屬性值變更。

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

若要更新附加屬性的值,請將附加屬性路徑放在括弧內。 此範例示範如何使用名稱 'TitleTextBlock' 更新 RelativePanel.AlignRightWithPanel 元素上的值。

<RelativePanel>
    <TextBlock x:Name="TitleTextBlock" Text="Title"/>
</RelativePanel>

...

<Setter Target="TitleTextBlock.(RelativePanel.AlignRightWithPanel)" Value="True"/>

備註

Setter.Target屬性可以用於StyleVisualState,但以不同方式使用。

  • Style中使用時,可以直接指定需要修改的屬性。
  • VisualState中使用時,Target 屬性必須指定 TargetPropertyPath (點語法,並明確指定目標元素和屬性) 。

適用於