image transistion
Posted
by
Jeff Main
on Stack Overflow
See other posts from Stack Overflow
or by Jeff Main
Published on 2011-01-12T02:36:04Z
Indexed on
2011/01/12
2:53 UTC
Read the original article
Hit count: 166
Hi all. I've gotten stuck again.
I've got an image (album cover) that I'll be changing in code behind, and wish to basicaly do the following.
When a new album cover image is determine and aquired, I want the current image in the image control to fade out, get updated with the new cover, and then fade back in.
I'm not seeing very many good examples on how to accomplish this in code behind.
The following was my latest failed attempt...
if (currentTrack != previousTrack)
{
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
image.UriSource = new Uri(Address, UriKind.Absolute);
image.EndInit();
Storyboard MyStoryboard = new Storyboard();
DoubleAnimation FadeOut = new DoubleAnimation();
FadeOut.From = 1.0;
FadeOut.To = 0.0;
FadeOut.Duration = new Duration(TimeSpan.FromSeconds(.5));
MyStoryboard.Children.Add(FadeOut);
Storyboard.SetTargetName(FadeOut, CoverArt.Name);
Storyboard.SetTargetProperty(FadeOut, new PropertyPath(Rectangle.OpacityProperty));
CoverArt.Source = image;
DoubleAnimation Fadein = new DoubleAnimation();
Fadein.From = 0.0;
Fadein.To = 1.0;
Fadein.Duration = new Duration(TimeSpan.FromSeconds(.5));
MyStoryboard.Children.Add(Fadein);
Storyboard.SetTargetName(Fadein, CoverArt.Name);
Storyboard.SetTargetProperty(Fadein, new PropertyPath(Rectangle.OpacityProperty));
MyStoryboard.Begin(this);
}
I'd prefer to do this in code behind simply because that is where I'm aquiring the image. Otherwise, I'm not sure how I'd trigger it.
An example would be greatly appriciated.
Thanks.
© Stack Overflow or respective owner