PowerShell and WPF: How to use an animated GIF

In this post, I will demonstrate how to use an animated GIF in your PowerShell and WPF GUI.

Add a picture (png or jpg)
You can easily add and display a picture in your GUI using the Image Control.
In the below example, I display my logo picture, which is a png file.
See below the result:

Add a GIF: not so easy
Now I will add the below GIF in my GUI.

For that I will replace the file in my Control, as below:
See below the result:

As you may noticed the GIF is display like a picture meaning there is no animation, it only shows the first picture.

Add a GIF: the good way
As mentioned before, by default the GIF will be displayed like a simple picture meaning without any animation.

How to display an animated GIF ?
Fir that we will use an external library called WpfAnimatedGif.
This one has been developed by Thomas Levesque.
See here the GitHub link.
See here, the blog of Thomas.

Now Let's see how to use this library.

Download the library
1. Download the Nuget exe, here.
2. Create a folder called WPF_Gif for instance
3. Open a PowerShell prompt and navigate to the WPF_Gif folder
4. Type the below commandline
5. This will download the library

6. You can find the dll to use in the folder

7. Copy the dll file in your project (in my case in a folder assembly)

PS1 Integration
We will load the WpfAnimatedGif.dll from our PowerShell script.
For that add the below line:

XAML Integration
Add the library namespace
We will add the appropriate namespace in the Window part to use the WpfAnimatedGif library.
1. Add the below line in the Window part
2. See below my Window part before
3. See below my Window part after

Add the GIF Control
To add a GIF in your GUI, we will use the same Image Control.
See below how to add it:
See below the result of the GUI after adding the library with the same GIF than before:

WPF_Guides 2066154217689364134

Publier un commentaire

Accueil item


Mes articles en français

Author of Books

PowerShell GUI & WPF Group

PowerShell GUI & WPF Group

Join the FPSUGR

Join the FPSUGR