I am currently developing a wpf c# application. I have added to event triggers to the xaml of the form to fade in when the window loads and fades out when the window closes.
H.B. solution is good but don't close effectively the window because Close() call window_Closing and loop. Here my working solution:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AlreadyFaded = false;
}
bool AlreadyFaded;
private void window_Closing(object sender, CancelEventArgs e)
{
if (!AlreadyFaded)
{
AlreadyFaded = true;
e.Cancel = true;
var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(1));
anim.Completed += new EventHandler(anim_Completed);
this.BeginAnimation(UIElement.OpacityProperty, anim);
}
}
void anim_Completed(object sender, EventArgs e)
{
Close();
}