Skip to content

Instantly share code, notes, and snippets.

@devth
Created October 18, 2010 17:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devth/632580 to your computer and use it in GitHub Desktop.
Save devth/632580 to your computer and use it in GitHub Desktop.
Fade animation in C# / WPF
DoubleAnimation animation = new DoubleAnimation();
animation.To = 0;
//animation.From = 1;
animation.Duration = TimeSpan.FromMilliseconds(ANIMATION_SPEED);
animation.EasingFunction = new QuadraticEase();
Storyboard sb = new Storyboard();
sb.Children.Add(animation);
c.Opacity = 1;
c.Visibility = Visibility.Visible;
Storyboard.SetTarget(sb, c);
Storyboard.SetTargetProperty(sb, new PropertyPath(Control.OpacityProperty));
sb.Begin();
sb.Completed += delegate(object sender, EventArgs e)
{
c.Visibility = Visibility.Collapsed;
};
@swharden
Copy link

Thanks for this! Please note that the Completed delegate must be defined before calling Begin()

https://stackoverflow.com/a/14183515/2399918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment