动画第一次工作

时间:2013-12-11 08:50:35

标签: xaml animation windows-phone-8 blend transitions

我想对一个对象进行旋转......问题是动画第一次工作!每次点击对象时它都应该工作......

这里是代码:

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:5">
                    <VisualTransition.GeneratedEasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
                <VisualTransition GeneratedDuration="0:0:5" To="Gira" x:Name="VT2">
                    <VisualTransition.GeneratedEasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
                <VisualTransition From="Gira" GeneratedDuration="0:0:5" x:Name="VT1">
                    <VisualTransition.GeneratedEasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="Gira">
                <Storyboard>
                    <DoubleAnimation Duration="0" To="45" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
                                     Storyboard.TargetName="image" d:IsOptimized="True" RepeatBehavior="Forever" />
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

这里是动画的控件:

<Image x:Name="image" HorizontalAlignment="Center" VerticalAlignment="Center" Source="/Assets/square.png" Height="450" RenderTransformOrigin="0.5,0.5" Tap="image_Tap">
       <Image.RenderTransform>
            <CompositeTransform />
       </Image.RenderTransform>

       <i:Interaction.Triggers>
            <i:EventTrigger EventName="Tap">
                <ec:GoToStateAction x:Name="StateGiraTap" StateName="Gira"/>
            </i:EventTrigger>
       </i:Interaction.Triggers>

</Image>

这里的代码背后是:

void image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    System.Windows.Interactivity.EventTrigger eventTrigger = System.Windows.Interactivity.Interaction.GetTriggers(image)[0] as System.Windows.Interactivity.EventTrigger;
    Microsoft.Expression.Interactivity.Core.GoToStateAction action = eventTrigger.Actions[0] as Microsoft.Expression.Interactivity.Core.GoToStateAction;

    action.UseTransitions = true;

    Gira.Storyboard.Seek(TimeSpan.Zero);
    Gira.Storyboard.Begin();
}

第一次工作,从第二次看到没有动画的最终结果...... 任何人都可以帮助我吗?

谢谢...

1 个答案:

答案 0 :(得分:0)

你将它设置为一个状态,并且它保持在该状态。而只是拥有你的故事板,只是触发它而不是在一个已经不存在的VisualState中。更像是;

<Object.Resources>
  <Storyboard x:Name="Gira">
    <DoubleAnimation Duration="0" To="45" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
                                     Storyboard.TargetName="image" d:IsOptimized="True" RepeatBehavior="Forever" />
  </Storyboard>
</Object.Resources>

然后把它关掉。

<i:Interaction.Triggers>
            <i:EventTrigger EventName="Tap">
                <ec:ControlStoryboardAction Storyboard="{StaticResource Gira}"/>
                <!--<ec:GoToStateAction x:Name="StateGiraTap" StateName="Gira"/>-->
            </i:EventTrigger>
</i:Interaction.Triggers>

希望这有帮助。