WpfAnimatedGif Documentation

repository·master·Indexed 20 days ago

https://github.com/xamlanimatedgif/wpfanimatedgif

A lightweight library for playing animated GIFs within standard WPF Image controls using attached properties. Features include frame accuracy, customizable repeat behavior via ImageBehavior.RepeatBehavior, and support for manual animation controls such as pause, resume, and seeking.

Tokens
788
Snippets
4
Records
5
Agent score
22%

What's inside WpfAnimatedGif

  1. Key features of WpfAnimatedGif

    master

    WpfAnimatedGif provides several capabilities for handling animations in WPF:

    • Standard Control Support: Animates GIFs within a normal Image control; no custom control is required.
    • Frame Accuracy: Takes actual frame duration from the GIF into account.
    • Customizable Repetition: Specify custom repeat behavior or use GIF metadata defaults.
    • Lifecycle Notifications: Provides notifications when an animation completes.
    • Design Mode Support: Supports animation preview in the Visual Studio designer (must be explicitly enabled).
    • Manual Control: Supports manual animation controls including pause, resume, and seeking.
  2. Display animated GIFs in XAML

    master

    To display an animated GIF in XAML, use the gif:ImageBehavior.AnimatedSource attached property on a standard WPF Image control. You must first map the gif namespace to http://wpfanimatedgif.codeplex.com.

    <Window x:Class="WpfAnimatedGif.Demo.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:gif="http://wpfanimatedgif.codeplex.com"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Image gif:ImageBehavior.AnimatedSource="Images/animated.gif" />
        </Grid>
    </Window>
  3. Configure GIF repeat behavior in XAML

    master

    You can control how many times a GIF repeats using the gif:ImageBehavior.RepeatBehavior attached property.

    • A value like 3x will repeat the animation 3 times.
    • If unspecified, the default is 0x, which instructs the player to use the repeat count defined in the GIF's metadata.
    <Image gif:ImageBehavior.RepeatBehavior="3x"
           gif:ImageBehavior.AnimatedSource="Images/animated.gif" />
  4. Set animated GIF source in C# code

    master

    To set an animated GIF source programmatically, use the ImageBehavior.SetAnimatedSource method. This method accepts a BitmapImage as the source.

    var image = new BitmapImage();
    image.BeginInit();
    image.UriSource = new Uri(fileName);
    image.EndInit();
    
    // img is your WPF Image control instance
    ImageBehavior.SetAnimatedSource(img, image);