UWP

时间:2019-04-19 09:38:37

标签: c# animation uwp

这是我的代码,用于为一个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();

它可以工作,由于某种原因,我只需要以编程方式就可以使用它。问题是我需要同时对多个控件进行动画处理。几个控件有解决方案吗?

1 个答案:

答案 0 :(得分:1)

您必须为此控件定义几个动画。

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