Click here to Skip to main content
14,981,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to play a movie on the start of my program then show a white rectangle quickly after the movie is finished then fade out the movie an rectangle with wpf animations.

What I did was I used the MediaEnded event of the media element to start the animation of the white rectangle fade out. But when i run the program it doesn't animate the opacity of the rectangle. it just waits for 1 second (the animation duration) and it disappears!

I have tried to use the XAML for creating the storyboard and playing it with triggers in Expression Blend but that didn't work either.
here is my code:

C#
//'movie' is the MediaElement and 'rect' is the white Rectangle that appears after the movie is finished and fades out

private void movie_MediaEnded(object sender, RoutedEventArgs e)
        {
            movie.Opacity = 0.0;
            rect.Opacity = 1.0;
            Storyboard fadeOut = new Storyboard();
            fadeOut.Completed += new EventHandler(fadeOut_Completed);
            DoubleAnimation fadeOutAnimation = new DoubleAnimation { Duration = TimeSpan.FromSeconds(1), To = 0.0 };
            Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath("Opacity"));
            fadeOut.Children.Add(fadeOutAnimation);
            fadeOut.Begin(rect);
        }

        void fadeOut_Completed(object sender, EventArgs e)
        {
            rect.Visibility = Visibility.Collapsed;
            movie.Visibility = Visibility.Collapsed;
        }


sorry for the long question!
thanks!
Posted
Updated 14-Dec-11 0:14am
v2
Comments
Slacker007 14-Dec-11 6:14am
   
Edit: tags, title, and formatting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900