简体   繁体   中英

Animation for several ui elements in UWP

This is my code to do animation (change opacity) for one ui element.

    var animation = new DoubleAnimation
    {
        To = 0.0,
        Duration = TimeSpan.FromSeconds(5),
        FillBehavior = FillBehavior.HoldEnd
    };

    Storyboard story = new Storyboard();
    Storyboard.SetTarget(animation, element1);
    Storyboard.SetTargetProperty(animation, "Opacity");
    story.Children.Add(animation);        
    story.Begin();

It works, for some reason I need to it only programmatically. The problem is I need to animate several controls at once. Is there any solution for several controls?

You would have to define several animations for this controls.

var animation1 = new DoubleAnimation
{
    To = 0.0,
    Duration = TimeSpan.FromSeconds(5),
    FillBehavior = FillBehavior.HoldEnd
};

var animation2 = new DoubleAnimation
{
    To = 0.0,
    Duration = TimeSpan.FromSeconds(5),
    FillBehavior = FillBehavior.HoldEnd
};

Storyboard.SetTarget(animation1, element1);
Storyboard.SetTargetProperty(animation1, "Opacity");

Storyboard.SetTarget(animation2, element2);
Storyboard.SetTargetProperty(animation2, "Opacity");

Storyboard story = new Storyboard();
story.Children.Add(animation1);
story.Children.Add(animation2);        
story.Begin();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM