WPF 应用 - WPF 播放 GIF 的两种方式
2024-08-30 07:01:07
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" />
/>
最新文章
- CSS3 速移动效果动画流畅无卡顿
- ASP.NET MVC 异常Exception拦截器Fillter
- 如何迁移Alwayson AG
- ARPSpoofing教程(四) - 捕获并分析数据包
- 初识socket
- EBS R12.2应用层关闭脚本的执行过程
- ZeroMQ(java)中的数据流SessionBase与SocketBase
- Spring Boot 以 jar 包方式运行在后台
- (单选后,显示相对应的div)点击免费没有变化,点击收费出现输入框
- asp.net(c#)中如何在前端用js写条件查询,且不用调用存储过程
- 单源最短路径的Bellman-Ford 算法
- Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心
- $stop and $finish in verilog
- jmap(Memory Map For Java)
- JavaScript MVC 框架[转载]
- PDF转图片工具
- CSS怎么在项目里引入自定义字体(@font-face)
- 6.0-uC/OS-III软件定时器管理
- 富文本之BootStrap-wysiwyg 带图片上传功能
- 和我一起学Effective Java之泛型
热门文章
- CF1478-B. Nezzar and Lucky Number
- Shell 元字符 &; 变量
- HDU 4746 Mophues(莫比乌斯反演)题解
- java变量、数据类型、运算符
- JavaScript 高级程序设计 (第4版) 思维导图/脑图 All In One
- React 性能优化 All In One
- 前端使用 js 如何实现大文件上传
- how to publish a UMD module
- JSDoc in action
- where is the storage location of the browser&#39;s HTTP cache? disk or memory