1. 使用 Winform 的 PictureBox

1.1 引用 dll

  • WindowsFormsIntegration.dll
  • System.Windows.Forms.dll
  • System.Drawing.dll

1.2 XMAl代码

<Window x:Class="TestGif.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestGif"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<wfi:WindowsFormsHost>
<winForms:PictureBox x:Name="PictureOfGif"></winForms:PictureBox>
</wfi:WindowsFormsHost>
</Grid>
</Window>

1.3 后台代码

public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
} private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.PictureOfGif.Image = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "Resources/Images/TestImage/3.gif");
}

1.4 存在问题

如果窗口的 AllowsTransparency 为 true,会导致 PictureBox 出不来,

可以尝试在 wfi:WindowsFormsHost 外面包一层 Popup,并把 Popup 的 AllowsTransparency 设置为 false

2. 使用 WpfAnimatedGif

2.1 引用 dll

  • WpfAnimatedGif.dll

    可以通过 Nuget 安装或直接手动引用 dll

2.2 Xaml 代码

<Window
...
xmlns:gif="http://wpfanimatedgif.codeplex.com"
...
> <Image gif:ImageBehavior.AnimatedSource="/Resources/Images/TestImage/3.gif" />
/>

最新文章

  1. CSS3 速移动效果动画流畅无卡顿
  2. ASP.NET MVC 异常Exception拦截器Fillter
  3. 如何迁移Alwayson AG
  4. ARPSpoofing教程(四) - 捕获并分析数据包
  5. 初识socket
  6. EBS R12.2应用层关闭脚本的执行过程
  7. ZeroMQ(java)中的数据流SessionBase与SocketBase
  8. Spring Boot 以 jar 包方式运行在后台
  9. (单选后,显示相对应的div)点击免费没有变化,点击收费出现输入框
  10. asp.net(c#)中如何在前端用js写条件查询,且不用调用存储过程
  11. 单源最短路径的Bellman-Ford 算法
  12. Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心
  13. $stop and $finish in verilog
  14. jmap(Memory Map For Java)
  15. JavaScript MVC 框架[转载]
  16. PDF转图片工具
  17. CSS怎么在项目里引入自定义字体(@font-face)
  18. 6.0-uC/OS-III软件定时器管理
  19. 富文本之BootStrap-wysiwyg 带图片上传功能
  20. 和我一起学Effective Java之泛型

热门文章

  1. CF1478-B. Nezzar and Lucky Number
  2. Shell 元字符 &amp; 变量
  3. HDU 4746 Mophues(莫比乌斯反演)题解
  4. java变量、数据类型、运算符
  5. JavaScript 高级程序设计 (第4版) 思维导图/脑图 All In One
  6. React 性能优化 All In One
  7. 前端使用 js 如何实现大文件上传
  8. how to publish a UMD module
  9. JSDoc in action
  10. where is the storage location of the browser&#39;s HTTP cache? disk or memory