XamlAnimatedGif / WpfAnimatedGif

A simple library to display animated GIF images in WPF, usable in XAML or in code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image load event not firing

jlocans opened this issue · comments

Seems that WpfAnimatedGif hides Image Load event.

I am dynamically changing image source in an endless loop.
In my project we use WpfAnimatedGif together with Transitionals with DataContext binding and in that case, load event is fired for all not .gif images and is fired only once only for the first .gif image.

I have created a simple wpf app for test purposes. Tried both with DataContext binding and setting source in code behind like this:

var image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(fileName);
image.EndInit();
ImageBehavior.SetAnimatedSource(img, image);

And in both cases, load event is fired only once in which Image.Source is null.
Am I missing something? If not, ideas for a possible workaround?
If you are interested in my test app, everything is in MyMainWindow files.

Hi,

I don't think it's an issue with WpfAnimatedGif... if you replace gif:ImageBehavior.AnimatedSource with just Source, you get the same behavior. Changing the Source of the Image control isn't supposed to trigger the Loaded behavior.

Hey.

Yes, you are right. Sorry. I guess I had impression that this was library's issue, because in our project the Load event was firing for all other image formats.

No problem 😉

Solution was very simple.
Just added ImageBehavior.AddAnimationLoadedHandler(img, Image_Loaded);
and everything works like a charm ;)

@Janjuks note that you can also do it in XAML:

<Image gif:ImageBehavior.AnimationLoaded="Image_Loaded" ...