Yang
Yang

Reputation: 6892

silverlight: fade away button?

I am making a button invisible once it gets clicked. Is there any nice animation (programmably from code behind) code that fade the button away instead of sudden disappearance?

Upvotes: 2

Views: 767

Answers (1)

lo5
lo5

Reputation: 460

This should help you. Just call 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();
    }

Upvotes: 4

Related Questions