WPF - 动画图像源更改

Rob*_*abe 4 wpf animation image keyframe

我对WPF很新,但我认为我需要做的事情相对简单.我需要创建一个图像"动画",我每隔0.25秒更换一个图像源.

我有一个名为"animation"的文件夹,图像为1到25 png live(名为1.png,2.png ... 25.png).每个图像都与我动画的不同帧相关联.

我想写xaml来将图像从1改为2,从2改为3,每隔0.25秒改变3到4等,直到它到达第25个图像,然后它应该循环回到开始.

我很可能需要写一些c#才能做到这一点.我希望它在可以与UI交互的线程上运行(如更新图像)但不阻止UI线程.

提前致谢!

Cle*_*ens 6

纯XAML解决方案可能看起来像这样,当然还有不同的图像和时序.

<Image>
    <Image.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard>
                <Storyboard RepeatBehavior="Forever">
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source"
                                                   Duration="0:0:2">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                            <DiscreteObjectKeyFrame.Value>
                                <BitmapImage UriSource="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"/>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                        <DiscreteObjectKeyFrame KeyTime="0:0:1">
                            <DiscreteObjectKeyFrame.Value>
                                <BitmapImage UriSource="C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg"/>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Image.Triggers>
</Image>
Run Code Online (Sandbox Code Playgroud)