I am using this code for gif Animating in seprate library and xaml code in my main project:
There is a much easier way to show an animated .gif in wpf - use the MediaElement
Example:
If you want the .gif to loop endlessly but it only specifies a limited amount of repeats in the .gif file, you can hook MediaEnded
and just restart the animation (Be sure to set the UnloadedBehavior
to Manual
):
private void myGif_MediaEnded(object sender, RoutedEventArgs e)
{
myGif.Position = new TimeSpan(0, 0, 1);
myGif.Play();
}