问题描述
我有一组在 for 循环中动态生成的图像.我的目标是为所有这些相同的图像添加相同的故事板动画.我创建了动画,但是在 for 循环中应用它时,它只能一个接一个地应用因为之前必须停止根动画.我怎样才能做到这一点?
I have a set of images which are generated dynamically in a for loop.My objective is to add same storyboard animation to all these same images.I created the animation but while applying it in for loop it can apply only one after another because root animation must stop before.How can I achieve this?
提前致谢
推荐答案
您只能对单个目标使用动画,因此您需要复制动画以将其应用于多个目标.一种选择是每次都在后面的代码中创建故事板.另一种方法是将故事板放在一个 DataTemplate 中,并为每个 Image 单独加载它.然后,您还可以将 Image 控件和 Storyboard 放在 UserControl 中,并将该 UserControl 用于每个图像(通过 DataTemplate 或任何其他方式).
You can only use an animation with a single target so you need to duplicate the animation to apply it to multiple targets. One option is to create the storyboard in code behind each time. Another is to put the storyboard in a DataTemplate and load it separately for each Image. Then you can also put the Image control and the Storyboard in a UserControl and use that UserControl for each image (via DataTemplate or any other way).
这篇关于如何在winRT中为动态创建的图像设置相同的动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!