【问题标题】:wpf storyboard animation lasts only 2 secondswpf故事板动画仅持续2秒
【发布时间】:2017-06-05 09:39:05
【问题描述】:

我有一个 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);

【问题讨论】:

    标签: c# wpf xaml storyboard


    【解决方案1】:

    从 Storyboard 中删除 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 2017-03-02
      • 2016-07-02
      • 2018-12-22
      • 2013-01-25
      • 1970-01-01
      • 2012-02-21
      相关资源
      最近更新 更多