0

I am developing a Visual Studio extension in C# and I would like to display a (waiting) transparent animated gif inside a tool window panel.

I have googled a lot and I only could find very complex solutions involving special dedicated libraries or some equivalent source code to add to my project. For example, I could find this post: How do I get an animated gif to work in WPF?. But I cannot understand why it would require such complex solutions for such a basic feature as animated gifs.

Can't XAML support natively animated gifs?

On my side I tried the following in my XAML file:

<Image Source="pack://application:,,,/MyPlugin;component/Resources/busy.gif" 
       Width="16" Height="16"/>

The image loads (although not animated) while Visual Studio is in edition mode. However, the image NEVER shows in the experimental instance.

What did I miss?

Stephane
  • 333
  • 1
  • 13
  • Possible duplicate of [How do I get an animated gif to work in WPF?](https://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf) – 500 - Internal Server Error Aug 26 '19 at 14:27
  • 1
    Hi! I saw this post. However, as said, isn't it any other solution than all this complex stuff for such a basic feature as displaying an animated gif? Not supported natively? – Stephane Aug 26 '19 at 14:31
  • You wouldn't work with gifs in wpf but with a [storyboard](https://learn.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/animation-overview). Gifs are not supported out of the box, so if you wish to use wpf, then use the tools available for you – Icepickle Aug 26 '19 at 14:59
  • Hi, any update for this issue? – LoLance Aug 28 '19 at 06:26

1 Answers1

-1

For example, I could find this post: How do I get an animated gif to work in WPF?. But I cannot understand why it would require such complex solutions for such a basic feature as animated gifs.

There're some easy ways to display .gif in wpf. For me, I use WpfAnimatedGif to do this.Simply install the nuget package and add the corresponding xmlns then the gif can display in wpf or vs extension.

For WpfAnimatedGif:

1.Add xmlns:gif="http://wpfanimatedgif.codeplex.com" to the xx.xaml.

2.<Image gif:ImageBehavior.AnimatedSource="xxx/xxx.gif" />

Then the .gif can display in the vs extension.

The format in my project:

<UserControl x:Class="VSIXProject2.ToolWindow1Control"
             ...
             xmlns:gif="http://wpfanimatedgif.codeplex.com"
             xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
             Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
             Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"
             Name="MyToolWindow">
    <Grid>
        <StackPanel Orientation="Vertical">
            ...
            <Image gif:ImageBehavior.AnimatedSource="pack://application:,,,/VSIXProject2;component/Resources/time.gif" Height="100" Width="200"/>
        </StackPanel>
    </Grid>
</UserControl>

Note: To display the image when debugging VS extensions, the source format should be pack://application:,,,/xxx;component/Resources/xxx.gif. It's the different behavior between normal wpf and ToolWindows in vsix. More details see this.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Hi Lance! Thanks for your reply. I installed the nuget package as you proposed and added the new xmlns sentence. It looks like the website has been transferred to github but the xmlns has still to refer the old one (the new one will issue an error). Unfortunately, it does not work and I get the following exception at startup: "Could not load file or assembly 'WpfAnimatedGif, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified." – Stephane Aug 29 '19 at 12:13
  • It do work in my working machine with VS2017, what's your vs version? I haven't had time to try it in VS2019. And according to the error message, you need to check if the assembly is in your xx.vsix package. Rename it to a xx.zip and check its content. – LoLance Aug 29 '19 at 13:45