silverlight:淡出按钮?

时间:2010-06-03 06:18:11

标签: silverlight animation

单击按钮后,我会使按钮不可见。是否有任何漂亮的动画(可编程代码来自代码)代码可以消除按钮而不是突然消失?

1 个答案:

答案 0 :(得分:4)

这应该对你有所帮助。只需致电FadeOut(myButton)

    private void FadeOut(UIElement fe, int seconds = 2)
    {
        DoubleAnimation animation = new DoubleAnimation() { To = 0, Duration = new Duration(new TimeSpan(0, 0, seconds)) };
        Storyboard sb = new Storyboard();
        sb.Children.Add(animation);
        Storyboard.SetTarget(animation, fe);
        Storyboard.SetTargetProperty(animation, new PropertyPath(UIElement.OpacityProperty));
        sb.Begin();
    }