我有一个WPF应用程序,其中包含一个具有圆形动画的椭圆。动画只运行2秒钟,我希望它能一直运行,直到我告诉故事板停止。
这是资源字典故事板定义:
<Storyboard x:Key="AnimateCircle" Duration="00:05:00">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="{Binding}">
<EasingColorKeyFrame KeyTime="0" Value="#FF212121"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="{Binding}">
<EasingColorKeyFrame KeyTime="0" Value="#FFF7F4F5"/>
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="{Binding}" Duration="00:05:00">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="359"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
这是我的WPF XAML代码:
<Ellipse
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
x:Name="AnimationCircle"
Margin="0,0,0,0"
Height="200" Width="200"
StrokeThickness="30"
Visibility="Visible"
RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
<Ellipse.Stroke>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF212121" Offset="0"/>
<GradientStop Color="#FFF7F4F5" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
这是启动动画的WPF C#代码:
sb = this.FindResource("AnimateCircle") as Storyboard;
Storyboard.SetTarget(sb, AnimationCircle);
sb.Begin(this);
答案 0 :(得分:3)
从故事板中删除Duration="00:05:00"
并像这样修改DoubleAnimationUsingKeyFrames
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="{Binding}" RepeatBehavior="Forever">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="359"/>
</DoubleAnimationUsingKeyFrames>