How do I get an animated gif to work in WPF?

前端 未结 18 1189
广开言路
广开言路 2020-11-22 12:16

What control type should I use - Image, MediaElement, etc.?

18条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 12:29

    Basically the same PictureBox solution above, but this time with the code-behind to use an Embedded Resource in your project:

    In XAML:

    
      
    
    

    In Code-Behind:

    public partial class ProgressIcon
    {
        public ProgressIcon()
        {
            InitializeComponent();
            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("My.Namespace.ProgressIcon.gif");
            var image = System.Drawing.Image.FromStream(stream);
            Loaded += (s, e) => _loadingPictureBox.Image = image;
        }
    }
    

提交回复
热议问题