参考自:https://www.cnblogs.com/liunlls/p/wpf-gif.html
思路:调用Winform中的picturebox控件显示gif格式图片
1. 添加引用
分别为:System.Drawing、System.Windows.Forms 和 WindowsFormsIntegration
添加完成后如下所示
2. 在XAML文件中Windows元素中添加下面两行代码
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
如下:
3. 此时可使用PictureBox控件
<Grid>
<wfi:WindowsFormsHost>
<winForms:PictureBox x:Name="PictureofGif"></winForms:PictureBox>
</wfi:WindowsFormsHost>
</Grid>
最后在cs文件中绑定gif图片即可。
效果图:
我这里做了一个水平垂直居中
<Grid>
<wfi:WindowsFormsHost HorizontalAlignment="Center" VerticalAlignment="Center">
<winForms:PictureBox x:Name="PictureofGif"></winForms:PictureBox>
</wfi:WindowsFormsHost>
</Grid>