Several ways that WPF displays GIF graphs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.