Using a Storyboard animation on a programmatically-added control

后端 未结 4 1820
不知归路
不知归路 2020-12-13 12:42

I\'m trying to fade in a new control to my application\'s \"app\" area which is programmatically added after the existing controls are removed. My code looks like this:

4条回答
  •  感动是毒
    2020-12-13 13:31

    I wouldn't hassle with the NameScopes etc. and would rather use Storyboard.SetTarget instead.

    var b = new Button() { Content = "abcd" };
    stack.Children.Add(b);
    
    var fade = new DoubleAnimation()
    {
        From = 0,
        To = 1,
        Duration = TimeSpan.FromSeconds(5),
    };
    
    Storyboard.SetTarget(fade, b);
    Storyboard.SetTargetProperty(fade, new PropertyPath(Button.OpacityProperty));
    
    var sb = new Storyboard();
    sb.Children.Add(fade);
    
    sb.Begin();
    

提交回复
热议问题