This project is read-only.

How to display a GIF from a URL link

Jan 22, 2012 at 5:38 PM


I have an issue  where I'm trying to load a GIF from a link passed to me in an RSS feed. Unlike a lot of the examples on here I am trying to do this through a listbox item when it is databound.

Currently I have the following in my XAML:


<ListBox x:Name="Weather">

                            <imagetools:AnimatedImage Source="{Binding WeatherIcon, Converter={StaticResource DisplayGIF}}" />

                            <TextBlock Name="temperatureBlock" Text="{Binding WeatherTemperatureSummary}" TextWrapping="Wrap" Margin="12,0,0,0" FontSize="{Binding HeadlineSize}" Foreground="{Binding WeatherTemperatureSummary, Converter={StaticResource StylesAndColours}}" />
                            <TextBlock Name="summaryBlock" Text="{Binding Summary, Converter={StaticResource RssTextTrimmer}}" TextWrapping="Wrap" Margin="12,-6,0,10" FontSize="{Binding SummarySize}" />



When the imagetools:AnimatedImage tag is databound it calls a class in my project DisplayGIF which is below:

using ImageTools;
using ImageTools.IO;
using ImageTools.IO.Gif;
using System.Windows.Data;

public class DisplayGIF : IValueConverter
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            ExtendedImage image = new ExtendedImage();
            image.UriSource = new Uri(value.ToString(), UriKind.Absolute);
            return image.ToBitmap();

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            throw new NotSupportedException();


The above results in a 'Image not loaded' message. I know I have to wait for the image to be downloaded from the link but I'm not sure how to go about this?

I can see in your examples that you use 'image_LoadingCompleted' but it's not clear what I am meant to put in there to return a bitmap.

Any help would be appreciated. I currently have this question on which I will update once I get it working :)



Jan 23, 2012 at 8:07 AM

ok, turns out that the images I was trying to link to were not Hot Link-able! so code was working but image source was denying me access!

A great code sample is over here for anyone interested: