WPF中使用MediaElement显示GIF

<MediaElement x:Name="myGif" MediaEnded="myGif_MediaEnded" UnloadedBehavior="Manual"     Source="file://C:Imageswaiting.GIF" LoadedBehavior="Play" Stretch="None"/>
<!--
Source="Images/waiting.GIF"
-->
    private void myGif_MediaEnded(object sender, RoutedEventArgs e)
    {
        myGif.Position = new TimeSpan(0, 0, 1);
        myGif.Play();
    }

  在xaml中MediaElement不能加载作为资源或内嵌的资源的GIF图片,这里指定的是全路径或相对路径。还有一种方法是把MediaElement封装成用户控件,在控件中对Source的资源路径进行加工。

原文地址:https://www.cnblogs.com/saybookcat/p/5191065.html