简体   繁体   English

同步播放动画的最佳方法?

[英]Best way to play animations synchronously?

My Application will download data from the web, whenever the user will trigger. 每当用户触发时,我的应用程序都会从​​Web下载数据。 The user can trigger multiple downloads. 用户可以触发多个下载。 Each download is listed in a stack panel an a busy icon is shown on each item which is rotating while downloading. 每次下载都在堆栈面板中列出,并且在下载时正在旋转的每个项目上都会显示一个忙碌图标。

<Image x:Name="rotatingCircle" Source="{StaticResource busy_icon}" Height="30" RenderTransformOrigin=".5,.5" Visibility="Visible">
            <Image.RenderTransform>
                <RotateTransform x:Name="AnimatedRotateTransform" Angle="0" />
            </Image.RenderTransform>
            <Image.Style>
                <Style>
                    <Style.Triggers>
                        <Trigger Property="Image.IsEnabled" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                Storyboard.TargetProperty="RenderTransform.Angle"
                                From="0"
                                To="360"
                                Duration="0:0:1"
                                RepeatBehavior="Forever"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Image.Style>
        </Image>

How can I synchronise the animation, so that every circle is rotating with the same angle, regardless when it was started? 如何同步动画,以使每个圆圈都以相同角度旋转,而不管它是何时开始的?

In my case it was enough to store Storyboards in a list. 就我而言,将故事板存储在列表中就足够了。 Every time when a animated icon was added I simply iterate through all Storyboards and started them again (sb.Begin()). 每次添加动画图标时,我都会遍历所有Storyboard,然后再次启动它们(sb.Begin())。 There is a small flicker, because every element is starting at the initial position, but they are running absolut synchronously. 闪烁很小,因为每个元素都从初始位置开始,但是它们绝对同步运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM