DDJ
DDJ

Reputation: 855

wpf loading a gif image animation

I wanted to do a simple button_click that would load an animated gif and have it loop 3 times.

The closest example which is not a Winform example, is Mediaelement, but how does one load it within the button click?

Can one point me to a tutorial?

<MediaElement  Height="113" 
               HorizontalAlignment="Left" 
               Name="mediaElement1" 
               Width="177" Source="giffy.gif" 
               LoadedBehavior="Play" 
               Stretch="Fill" SpeedRatio="1" IsMuted="False" />

Upvotes: 1

Views: 4254

Answers (2)

Caleb Sewcharran
Caleb Sewcharran

Reputation: 63

I have tried using the library as specified in the accepted answer and it did not work. I've done some digging and found out the author of the package had remade the package and called it XamlAnimatedGif

In the blog, the author gives reasons as to why he had to change the old package. However, he did not give much information regarding the implementation of it.

The implementation I've been able to get to work is as below

xml namespace reference

xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif"

xaml code for loading a gif

<Image gif:AnimationBehavior.SourceUri="/Assets/loading.gif"
       gif:AnimationBehavior.RepeatBehavior="3x"/>

Hopefully this helps

Upvotes: 2

ΩmegaMan
ΩmegaMan

Reputation: 31606

I have used this one and it is easily installed via the Nuget installer into the project.

Nuget WpfAnimatedGif

Their github page WPF Animated GIF specifies how to set it to loop x number of times.

Upvotes: 3

Related Questions