Does playing GIF for WPF hurt?

NuGet 包:WpfAnimatedGif。
今天介绍一个用于在 WPF 中显示动态 GIF 图片的库,可在 XAML 或代码中使用:WpfAnimatedGif。
简单易用:在 XAML 中,使用AnimatedSource附加属性设置需要显示的 gif 图片(替换Source属性):
<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>

您还可以指定重复行为(默认为0x,这意味着它将使用来自 GIF 元数据的重复计数):
<image
gif:ImageBehavior.RepeatBehavior="3x"
gif:ImageBehavior.AnimatedSource="Images/animated.gif"
/>

Of course, you can also set gif images in your code:
var image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(fileName);
image.EndInit();
ImageBehavior.SetAnimatedSource(img, image);

有关使用的更多详细信息,请参阅wiki。
characteristics
- 未增加新的控件,在 WPF 原生的
Image控件中添加附加属性即实现了 gif 图片动态加载功能 - Consider actual frame duration
- Repeat behavior can be specified; if not, repeat counting from GIF metadata is used
- Notify when the animation is completed, and can be used to do some specific things after the animation is completed
- Animation preview in design mode (must be explicitly enabled)
- Support manual animation control (pause/resume/jump)