简体   繁体   中英

WPF animated GIF Source change on runtime .. but remains static on source change

Hi guys please help with this ... What exactly i am trying to do is .. changing the ANIMATED GIF IMAGE SOURCE on runtime. However the image change is happening but as the image is animated its getting blacked out somehow may be the thread is busy !

Here's the code !

var image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(@"/BackgroundWorkerWpf;component/Media/p1.gif", UriKind.Relative);
image.EndInit();
ImageBehavior.SetAnimatedSource(img, image);

The image source is changed as per required but the image remains static just like its a snap of the original GIF Image.THANKS IN ADVANCE :)

PS : I AM USING THE REFERENCE LIB FROM CODEPLEX

After you changed property animated source you should invoke ImageBehavior.SetRepeatBehavior method.

Try following code:

var image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(@"/BackgroundWorkerWpf;component/Media/p1.gif", UriKind.Relative);
image.EndInit();
ImageBehavior.SetAnimatedSource(img, image);
ImageBehavior.SetRepeatBehavior(img, new RepeatBehavior(0));
ImageBehavior.SetRepeatBehavior(img, RepeatBehavior.Forever);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM