i'm trying to do an animation before the visibility changes to collapsed.
I'm trying to accomplish a fade in/fade out effect when the visibility is changed. I have no problem with fade in, because the visibility changes before my animation (which is good).
Here's my code right now:
private void LoginOverlay_OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (this.Visibility == Visibility.Visible)
{
//Fade in ... this is working
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 1;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath(OpacityProperty));
Storyboard.SetTarget(da, this);
sb.Begin();
}
else
{
//Fade out ... not working
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.From = 1;
da.To = 0;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath(OpacityProperty));
Storyboard.SetTarget(da, this);
sb.Begin();
}
}