我对WPF还是很陌生,但是我认为我需要做的相对简单。我需要创建一个图像“动画”,在这里每隔0.25秒更改一次图像源。
我有一个名为“ animation”的文件夹,其中包含1到25 png实时图像(名为1.png,2.png ... 25.png)。每个图像都与我动画的不同帧相关。
我想编写xaml以每.25秒将图像从1更改为2,从2更改为3,将3更改为4等,直到它到达第25张图像,然后它应该循环回到开始。
我最有可能需要编写一些C#来做到这一点。我希望它在可以与UI交互的线程上运行(如更新图像),但不阻止UI线程。
提前致谢!
一个纯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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句