Wpf UWP,故事板访问controltemplate中的路径的正确语法是什么?

Wpf UWP,故事板访问controltemplate中的路径的正确语法是什么?,wpf,xaml,uwp-xaml,Wpf,Xaml,Uwp Xaml,我正在使用UWP windows 10 phone应用程序,在获取脚本以旋转转换按钮控件模板中定义的路径时遇到问题 我更愿意在xaml中实现这一点。我是否为storyboard.targetproperty指定quazi xaml路径?=>viewer.navbutton.PART\u箭头 <Grid x:Name="layoutRoot" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> &l

我正在使用UWP windows 10 phone应用程序,在获取脚本以旋转转换按钮控件模板中定义的路径时遇到问题

我更愿意在xaml中实现这一点。我是否为storyboard.targetproperty指定quazi xaml路径?=>viewer.navbutton.PART\u箭头

<Grid x:Name="layoutRoot" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.1"/>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="ShowNav">
                <VisualState.Setters>
                    <Setter Target="navigation.(FrameworkElement.Height)" Value="Auto"/>
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="HideNav">
                <VisualState.Setters>
                    <Setter Target="navigation.(FrameworkElement.Height)" Value="0"/>
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Resources>
        <Storyboard x:Name="rotateStoryBoard">
            <DoubleAnimation Storyboard.TargetName="rotateDownArrow"
                            Storyboard.TargetProperty="Angle"
                            From="0"
                            To="90"
                            Duration="0:0:2"/>
        </Storyboard>
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" x:Name="navigation">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBox Grid.Column="1" x:Name="navbar" Margin="0,0,0,0"/>
        <Button Grid.Column="0"  x:Name="refresh_Copy"
            VerticalAlignment="Top"
            Content="Refresh"
            Click="refresh_Click"
            RenderTransformOrigin="1.457,0.562" />
    </Grid>
    <Grid Grid.Row="1" x:Name="viewer">
        <Button x:Name="navButton"
                HorizontalAlignment="Center" 
                VerticalAlignment="Top"
                Canvas.ZIndex="1"
                Click="navButton_Click">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid HorizontalAlignment="Center">
                                    <Path x:Name="PART_Circle"
                                          Fill="{ThemeResource ButtonBackgroundThemeBrush}"
                                          Stroke="{ThemeResource ButtonBackgroundThemeBrush}" 
                                          StrokeThickness="1.5" 
                                          Data="M0,0 A30,30 0 0 0 60,0"/>
                                    <Path x:Name="PART_Arrow" 
                                          Stroke="GreenYellow" 
                                          StrokeThickness="1.5" 
                                          Data="M12,6 L30,18 L48,6">
                                        <Path.RenderTransform>
                                            <RotateTransform x:Name="rotateDownArrow" 
                                                             Angle="0"
                                                             CenterX="30"
                                                             CenterY="12"/>
                                        </Path.RenderTransform>
                                    </Path>
                                </Grid>
                            </ControlTemplate>

                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
        <WebView x:Name="Web"
                 Grid.Row="1"
                 Grid.Column="0"
                 Grid.ColumnSpan="2"
                 NavigationCompleted="Web_NavigationCompleted"
                 ScriptNotify="Web_OnScriptNotify"
                 Canvas.ZIndex="0"/>
    </Grid>

</Grid>

故事板访问controltemplate中的路径的正确语法是什么

要访问的
路径
控件位于内部。根据的“模板”部分中的XAML名称范围:

XAML中的模板提供了以一种简单的方式重用和重新应用内容的能力,但模板也可能包括在模板级别定义名称的元素。同一个模板可能在一个页面中使用多次。因此,模板定义自己的XAML名称范围,独立于应用样式或模板的包含页面

因此
ControlTemplate
有自己的名称作用域,您不能通过
Name
直接访问其中的控件。您可能需要使用类来帮助您访问控件

但是如果你想让情节提要可以访问控件,你可以让情节提要与控件位于同一模板中,并且它们将位于同一范围内

此外,
按钮
包含四个默认值,建议通过一个视觉状态触发情节提要。下面的代码将情节提要放入ControlTemplate,当按下按钮时会触发该脚本,您可以引用该按钮

<Grid
    x:Name="layoutRoot"
    Padding="50"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
   ...
    <Grid x:Name="viewer" Grid.Row="1">
        <Button
            x:Name="navButton"
            HorizontalAlignment="Center"
            VerticalAlignment="Top"
            Canvas.ZIndex="1"
            Click="navButton_Click">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid HorizontalAlignment="Center"> 
                                    <Grid.Resources>
                                        <Storyboard x:Name="rotateStoryBoard">
                                            <DoubleAnimation
                                                BeginTime="0:0:0"
                                                Duration="0:0:2"
                                                From="0"
                                                Storyboard.TargetName="rotateDownArrow"
                                                Storyboard.TargetProperty="Angle"
                                                To="90" />
                                        </Storyboard>
                                    </Grid.Resources>
                                    <Path
                                        x:Name="PART_Circle"
                                        Fill="{ThemeResource ButtonBackgroundThemeBrush}"
                                        Stroke="{ThemeResource ButtonBackgroundThemeBrush}"
                                        StrokeThickness="1.5"
                                        Data="M0,0 A30,30 0 0 0 60,0" />
                                    <Path
                                        x:Name="PART_Arrow"
                                        Stroke="GreenYellow"
                                        StrokeThickness="1.5"
                                        Data="M12,6 L30,18 L48,6">
                                        <Path.RenderTransform>
                                            <RotateTransform x:Name="rotateDownArrow" Angle="0" CenterX="30" CenterY="12" />
                                        </Path.RenderTransform>
                                    </Path>
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualState x:Name="Pressed">
                                                <Storyboard>
                                                    <DoubleAnimation
                                                        BeginTime="0:0:0"
                                                        Duration="0:0:2"
                                                        From="0"
                                                        Storyboard.TargetName="rotateDownArrow"
                                                        Storyboard.TargetProperty="Angle"
                                                        To="90" />
                                                </Storyboard>
                                            </VisualState> 
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
...
</Grid>

...
...
故事板访问controltemplate中的路径的正确语法是什么

要访问的
路径
控件位于内部。根据的“模板”部分中的XAML名称范围:

XAML中的模板提供了以一种简单的方式重用和重新应用内容的能力,但模板也可能包括在模板级别定义名称的元素。同一个模板可能在一个页面中使用多次。因此,模板定义自己的XAML名称范围,独立于应用样式或模板的包含页面

因此
ControlTemplate
有自己的名称作用域,您不能通过
Name
直接访问其中的控件。您可能需要使用类来帮助您访问控件

但是如果你想让情节提要可以访问控件,你可以让情节提要与控件位于同一模板中,并且它们将位于同一范围内

此外,
按钮
包含四个默认值,建议通过一个视觉状态触发情节提要。下面的代码将情节提要放入ControlTemplate,当按下按钮时会触发该脚本,您可以引用该按钮

<Grid
    x:Name="layoutRoot"
    Padding="50"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
   ...
    <Grid x:Name="viewer" Grid.Row="1">
        <Button
            x:Name="navButton"
            HorizontalAlignment="Center"
            VerticalAlignment="Top"
            Canvas.ZIndex="1"
            Click="navButton_Click">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid HorizontalAlignment="Center"> 
                                    <Grid.Resources>
                                        <Storyboard x:Name="rotateStoryBoard">
                                            <DoubleAnimation
                                                BeginTime="0:0:0"
                                                Duration="0:0:2"
                                                From="0"
                                                Storyboard.TargetName="rotateDownArrow"
                                                Storyboard.TargetProperty="Angle"
                                                To="90" />
                                        </Storyboard>
                                    </Grid.Resources>
                                    <Path
                                        x:Name="PART_Circle"
                                        Fill="{ThemeResource ButtonBackgroundThemeBrush}"
                                        Stroke="{ThemeResource ButtonBackgroundThemeBrush}"
                                        StrokeThickness="1.5"
                                        Data="M0,0 A30,30 0 0 0 60,0" />
                                    <Path
                                        x:Name="PART_Arrow"
                                        Stroke="GreenYellow"
                                        StrokeThickness="1.5"
                                        Data="M12,6 L30,18 L48,6">
                                        <Path.RenderTransform>
                                            <RotateTransform x:Name="rotateDownArrow" Angle="0" CenterX="30" CenterY="12" />
                                        </Path.RenderTransform>
                                    </Path>
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualState x:Name="Pressed">
                                                <Storyboard>
                                                    <DoubleAnimation
                                                        BeginTime="0:0:0"
                                                        Duration="0:0:2"
                                                        From="0"
                                                        Storyboard.TargetName="rotateDownArrow"
                                                        Storyboard.TargetProperty="Angle"
                                                        To="90" />
                                                </Storyboard>
                                            </VisualState> 
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
...
</Grid>

...