Is it possible to start same animation for different controls at same start time

蹲街弑〆低调 提交于 2019-12-13 02:13:28

问题


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>

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();
    }

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


回答1:


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.



来源:https://stackoverflow.com/questions/24738976/is-it-possible-to-start-same-animation-for-different-controls-at-same-start-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!