是否可以在同一开始时间为不同的控件开始相同的动画 [英] Is it possible to start same animation for different controls at same start time

查看:104
本文介绍了是否可以在同一开始时间为不同的控件开始相同的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有双重动画的故事板,

I have a story board with double animation,

<Storyboard x:Name="Storyboard1">
        <DoubleAnimation From="0" To="200" Duration="0:0:2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)">

        </DoubleAnimation>
    </Storyboard>

而我只是动态添加TargetNameProperty,

and I just adding TargetNameProperty dynamically,

 private void set_animation_for_images(string target_name)
    {
        Storyboard1.Stop();

        Storyboard1.SetValue(Storyboard.TargetNameProperty, target_name);

        Storyboard1.Begin();
    }

这里 是否可以在同一开始时间针对不同图像连续调用set_animation_for_images()方法?

Here is it possible to call this set_animation_for_images() method continuously for different image at same starting time?

推荐答案

由于只有一个故事板,因此一次只能针对一个元素.要一次定位多张图片,您可能需要在代码中生成整个图片:

Because you only have the one storyboard, you can only have it targeting one element at a time. To target multiple images at a time, you may need to generate the whole thing in code:

private void animateImage(string target)
{
     Storyboard testStoryboard = new Storyboard();
     ...

     testStoryboard.SetValue(Storyboard.TargetNameProperty, target_name);
     testStoryboard.Begin();
}

如果所有图像都在容器中,则始终可以将容器本身作为目标,但这可能无法获得想要的效果.

If all the images are in a container, you could always target the container itself, but that might not get the effect you want.

这篇关于是否可以在同一开始时间为不同的控件开始相同的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆