开发者

WPF doubleanimation : animate in steps?

In my current application I have this little animation. It makes a full 360 degrees rotation of a canvas and works fine.

<DoubleAnimation
 Storyboard.TargetName="WaitCanvas" 
 Storyboard.TargetProperty="(Canvas.RenderTransform).(TransformGroup.Children)[0]  
 .(RotateTransform.Angle)" 
 From="0" To="360" Dura开发者_如何学编程tion="0:0:2"
 AutoReverse="False" RepeatBehavior="Forever" />

But the thing I want to do is not a smooth animation but animation is steps of 22.5 degrees each. How can this be done?


You could use a DoubleAnimationUsingKeyFrames and make two keyframes for each increment of 22.5 degrees at the same point in time.


Adding the XAML example which I was actually searching for.

<Storyboard
    BeginTime="00:00:00"
    RepeatBehavior="Forever"
    Storyboard.TargetName="WaitCanvas" 
    Storyboard.TargetProperty="(Canvas.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
    <DoubleAnimationUsingKeyFrames Duration="0:0:2">
        <DoubleKeyFrameCollection>
            <DiscreteDoubleKeyFrame KeyTime="0:0:0.000" Value="0" />
            <DiscreteDoubleKeyFrame KeyTime="0:0:0.125" Value="22.5" />
            <DiscreteDoubleKeyFrame KeyTime="0:0:0.250" Value="45" />
            <DiscreteDoubleKeyFrame KeyTime="0:0:0.375" Value="67.5" />
            <DiscreteDoubleKeyFrame KeyTime="0:0:0.500" Value="90" />
            <DiscreteDoubleKeyFrame KeyTime="0:0:0.625" Value="110.5" />
            <!-- ... -->
        </DoubleKeyFrameCollection>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>


Even easier, use the DoubleAnimation "By" property, as in:

<DoubleAnimation 
 Storyboard.TargetName="WaitCanvas"  
 Storyboard.TargetProperty="(Canvas.RenderTransform).(TransformGroup.Children)[0]   
 .(RotateTransform.Angle)"  
 From="0" To="360" By="22.5" Duration="0:0:2"
 AutoReverse="False" RepeatBehavior="Forever" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜