简体   繁体   English

UWP中几个ui元素的动画

[英]Animation for several ui elements in UWP

This is my code to do animation (change opacity) for one ui element. 这是我的代码,用于对一个ui元素进行动画处理(更改不透明度)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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