How to find the name of the grandson object in the animation storyboard?

奇 卢 181 Reputation points
2021-02-14T14:02:03.867+00:00
 <VisualState x:Name="Flipped">
                  <Storyboard>
                    <DoubleAnimation Duration="0" To="180" Storyboard.TargetProperty="Angle"
                                     Storyboard.TargetName="Rota"/>
                  </Storyboard>
                </VisualState>
...
...
           <ToggleButton Name="FlipButton">
          <ToggleButton.Template>
            <ControlTemplate TargetType="{x:Type ToggleButton}">
              <Grid>
                <Ellipse Width="25" Height="25" Fill="LightBlue" Stroke="Gray" StrokeThickness="1"></Ellipse>
                <Path Data="M2,6 l0 10 l13 -5z" Stroke="Black" StrokeThickness="1" Fill="Cyan"
                      HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">
                  <Path.RenderTransform>
                    <RotateTransform x:Name="Rote" Angle="0"></RotateTransform>
                  </Path.RenderTransform>
                </Path>
              </Grid>
            </ControlTemplate>
          </ToggleButton.Template>
        </ToggleButton>

When I switched the visual state of the control to "flipped", I was prompted that I couldn't find the name of "rota". Because I want to rotate the Path object in the button, do you know what to do?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
{count} votes

Accepted answer
  1. DaisyTian-1203 11,621 Reputation points
    2021-02-16T02:36:48.85+00:00

    I do some updates for your code like below:

     <StackPanel>  
            <ToggleButton Name="FlipButton">  
                <ToggleButton.Template>  
                    <ControlTemplate TargetType="{x:Type ToggleButton}">  
                        <Grid>  
                            <VisualStateManager.VisualStateGroups>  
                                <VisualStateGroup x:Name="CommonStates">  
                                    <VisualStateGroup.Transitions>  
                                        <VisualTransition GeneratedDuration="0:0:1" To="MouseOver" />  
                                        <VisualTransition GeneratedDuration="0:0:1" To="Normal" />  
                                    </VisualStateGroup.Transitions>  
                                    <VisualState x:Name="Normal" />  
                                    <VisualState x:Name="MouseOver">  
                                        <Storyboard>  
                                            <DoubleAnimation Duration="0:0:1" To="180"  Storyboard.TargetProperty="Angle" Storyboard.TargetName="Rota"/>  
                                        </Storyboard>  
                                    </VisualState>  
                                </VisualStateGroup>  
                            </VisualStateManager.VisualStateGroups>  
                              
                            <Ellipse Width="80" Height="25" Fill="LightBlue" Stroke="Gray" StrokeThickness="1"></Ellipse>  
                            <Path Data="M2,6 l0 10 l13 -5z" Stroke="Black" StrokeThickness="1" Fill="Cyan" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">  
                                <Path.RenderTransform>  
                                    <RotateTransform x:Name="Rota" Angle="0"></RotateTransform>  
                                </Path.RenderTransform>  
                            </Path>  
                        </Grid>  
                    </ControlTemplate>  
                </ToggleButton.Template>  
            </ToggleButton>  
        </StackPanel>  
    

    And the result picture is:
    68338-2.gif


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful