I need to display an animated GIF in my metro app, but I can't find any control that allows it. (I tried Image
, MediaElement
and MediaPlayer
from the Player Framework)
Is it possible somehow to display an animated GIF?
I need to display an animated GIF in my metro app, but I can't find any control that allows it. (I tried Image
, MediaElement
and MediaPlayer
from the Player Framework)
Is it possible somehow to display an animated GIF?
I just released a library to play animated GIFs: XamlAnimatedGif. You just need to set an attached property on a standard
Image
control:(the xmlns mapping is
xmlns:gif="using:XamlAnimatedGif"
)In works on WPF, Windows 8.1 and Windows Phone 8.1
Here You have a good tutorial how to insert gif into Metro Style App:
http://advertboy.wordpress.com/2012/05/08/animated-gifs-in-xamlc/
But simplest way is use this project:
http://imagetools.codeplex.com/
While I haven't checked if it works and it might not work for you due to airspace issues - you could try hosting your gif in a WebView control. It might be a lot easier than the otherwise better solutions proposed by Norbert and Carl.
As @Filip Skakun said
WebView
method works. Sure it's "hack" but all these libraries and decoding on fly is slow, animation flickers (at least in windows phone). Using WebView gives you ability to host animated gifs with transparent background. To use WebView gif rendering approach create html page in your project:CSS is important - because it disables zoom / scrolling / touch-move of WebView (which isn't desirable in most cases). Add animated gifs to same folder (where html sits). Xaml code:
The only drawback is that you "lose gestures" on area which
WebView
occupy (and you can't useWebViewBrush
because you would lose animation).This can't be natively done but you can check out
http://imagetools.codeplex.com/
which does all you want. Also you can check this
http://blogs.msdn.com/b/jstegman/archive/2009/09/08/silverlight-3-sample-updates.aspx
which contains a GIF Decoder library
You can achieve this natively by using the BitmapDecoder class in the .NET Framework. I have an example on my blog, that shows how to implement an AnimationControl that is able to show animated GIFs from a ressource gif file. Check out: http://www.henrikbrinch.dk/Blog/2013/02/21/Windows-8---GIF-animations--the-RIGHT-way