Using MediaElement
One limitation of this approach is that the picture path must be an absolute path
<Source= "file://c:\129.gif"/>
And you need to set him to loop.
<Source= "File://c:\129.gif" mediaended= "Mediaelement_ mediaended "/>
Private void Mediaelement_mediaended (object sender, RoutedEventArgs e) { ((MediaElement) sender). Position= ((MediaElement) sender). Position.add (Timespan.frommilliseconds (1)); }
Through the PictureBox control in WinForm
This way you can specify a relative path; First, you need to add an assembly reference to the window in a WPF program: System.Drawing.dll, System.Windows.Forms.dll and WindowsFormsIntegration.dll
After the reference type, you can use the PictureBox in WinForm in your XAML code.
Xmlns:wfi = " clr-namespace:system.windows.forms.integration;assembly=windowsformsintegration "xmlns:winforms =" clr-namespace: System.windows.forms;assembly=system.windows.forms "
< Wfi:windowsformshost > < x:name= "Pictureofgif"></winforms:picturebox> </wfi:windowsformshost>
Binding a picture in the program Load event
void Mainwindow_loaded (object sender, RoutedEventArgs e) { this. Pictureofgif.image = System.Drawing.Image.FromFile ("images/129.gif"); }
Wpfanimatedgif
Can be installed via console or NuGet
Install-package Wpfanimatedgif
xmlns:gif= "Http://wpfanimatedgif.codeplex.com"
<image gif:imagebehavior.animatedsource="images/animated.gif" />
GitHub Address: Https://github.com/XamlAnimatedGif/WpfAnimatedGif
Related documents:
https://nnish.com/tag/animated-gif-in-wpf/
https://social.msdn.microsoft.com/Forums/vstudio/en-US/93d50a97-0d8d-4b18-992e-cd3200693337/ How-to-use-an-animated-gif?forum=wpf
Several ways that WPF displays GIF graphs