Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimated gif within a WPF MediaElement stops animating after a few frames
    primarykey
    data
    text
    <p>I need to display some media in a WPF project. The media could be a jpeg, a gif, a png, a bmp or a wmv movie. So I'm hoping to use a MediaElement to do the diplaying. The problem is I can't get an animated gif to work properly.</p> <p>I've seen a load of questions on here discussing how to display animated gifs within WPF applications, specifically:</p> <p>1) <a href="https://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf/213786#213786">Embed a windows forms Picture box within the app</a>, which works ok, but the picture box doesn't scale properly when hosted within a ViewBox, so I can't use that<br> 2) <a href="https://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf">Create a custom GifImage which inherits from Image and do the animation myself</a>. This works ok, but it means I need to worry about what type of media I am displaying, instead of just asking the element to deal with it (though I guess I could customise the object even further if I wanted to so it knew how to deal with all sorts of media). Also I think that some animated gifs only store the bit that has changed in each frame, so displaying the frame doesn't work properly - this one for instance: <a href="http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif" rel="nofollow noreferrer">http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif</a>)<br> 3) <a href="https://stackoverflow.com/questions/4510364/how-a-continuous-play-gif-file-in-wpf">Use a MediaElement and set up a trigger with a storyboard to loop the gif infinitely</a>.</p> <p>The 3rd method is the one I'm trying to get working as it (ostensibly...) seems like the easiest method. However, whatever I do, I can't seem to get the animated gif to loop - in fact, it seems to get stuck after 3 frames. The code is below:</p> <pre><code>&lt;Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication4" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid&gt; &lt;MediaElement Name="yourMediaElement"&gt; &lt;MediaElement.Triggers&gt; &lt;EventTrigger RoutedEvent="MediaElement.Loaded"&gt; &lt;EventTrigger.Actions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;MediaTimeline Source="http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif" Storyboard.TargetName="yourMediaElement" RepeatBehavior="Forever" /&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger.Actions&gt; &lt;/EventTrigger&gt; &lt;/MediaElement.Triggers&gt; &lt;/MediaElement&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>I've tried the above with different animated gifs (these two: <a href="http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif" rel="nofollow noreferrer">http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif</a> and <a href="http://www.gifanimations.com/GA/image/animations/aliens/alien-01.gif" rel="nofollow noreferrer">http://www.gifanimations.com/GA/image/animations/aliens/alien-01.gif</a>), referencing them both directly from the internet, and locally (having downloaded and linked to them in a direct path to the file on the disk), but in all cases, after a few frames, the gif stops animating.</p> <p>Am I doing something wrong here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload