C# version: http://code.msdn.microsoft.com/CSWPFAnimatedImage-88b938d5
VB version: http://code.msdn.microsoft.com/VBWPFAnimatedImage-be1e0211
Today’s code sample demonstrates how to display a series of photos just like a digital picture frame with a "Wipe" effect in WPF.
You can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.
The sample demonstrates how to display a series of photos just like a digital picture frame with a "Wipe" effect in WPF.
Running the Sample
Press F5 to run this application, you will see that the window displays a series of photos just like a digital picture frame with a "Wipe" effect.
Using the Code
- Add two Image controls named myImage1 and myImage2 on a Window. The myImage1 lies on top of the myImage2.
- Set the OpacityMask of the myImage1 to a LinearGradientBrush. Add two GradientStop in the LinearGradientBrush.
- Add two Storyboards in the resource dictionary of the Window. One storyboard is named VisibleToInvisible. It animates the two GradientStop above to hide themyImage1. The other storyboard is named InvisibleToVisible. It animates thetwo GradientStop to show the myImage1.
- Create a collection of type List<BitmapImage> and add images to be shown in the collection when the Window is loaded.
- Subscribe the Completed event of the two storyboards.
- In the Completed event handler of the VisibleToInvisible storyboard, changethe Source of the myImage1 to the next image to be shown. Get the InvisibleToVisible storyboard from the resource dictionary and start it.
- In the Completed event handler of the InvisibleToVisible storyboard, changethe Source of the myImage2 to the next image to be shown. Get the VisibleToInVisible storyboard from the resource dictionary and start it.