Skip to content

Instantly share code, notes, and snippets.

@nasal
Created January 6, 2015 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasal/4ada380fcf4c8032f1fe to your computer and use it in GitHub Desktop.
Save nasal/4ada380fcf4c8032f1fe to your computer and use it in GitHub Desktop.
C#: Fade out animation
var myControl = ControlName;
var a = new DoubleAnimation
{
From = 1.0,
To = 0.0,
FillBehavior = FillBehavior.Stop,
BeginTime = TimeSpan.FromSeconds(2),
Duration = new Duration(TimeSpan.FromSeconds(0.5))
};
var storyboard = new Storyboard();
storyboard.Children.Add(a);
Storyboard.SetTarget(a, myControl);
Storyboard.SetTargetProperty(a, new PropertyPath(OpacityProperty));
storyboard.Completed += delegate { myControl.Visibility = Visibility.Hidden; };
storyboard.Begin();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment