Created
October 18, 2010 17:00
-
-
Save devth/632580 to your computer and use it in GitHub Desktop.
Fade animation in C# / WPF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! Please note that the
Completed
delegate must be defined before callingBegin()
https://stackoverflow.com/a/14183515/2399918