Animated gif in WPF MediaElement stops animation after several frames

I need to display some media in a WPF project. Media can be jpeg, gif, png, bmp or wmv movie. Therefore, I hope to use MediaElement to do diplaying. The problem is that I cannot get the animated gif to work correctly.

I saw a lot of questions discussing how to display animated gifs in WPF applications, in particular:

1) Insert the form window into the image window in the application , which works fine, but the image window does not scale properly when placed in the ViewBox, so I can not use this 2) Create your own GifImage, which inherits from Image and makes the animation itself . This works fine, but that means I need to worry about what type of media I am showing, rather than just asking the item to handle it (although, I think, I could adjust the object even further if I wanted to he knew how to communicate with all kinds of media). Also I think that some animated gifs only store the bit that was changed in each frame, so the frame display does not work properly - for example, this:http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif )
3) Use MediaElement and set up a trigger with a frame for an endless loop of gifs .

The third method is the one I'm trying to get, since it (supposedly ...) seems like the easiest method. However, no matter what I do, I can't get the animated gif to loop - it actually seems to get stuck after three frames. Code below:

<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">
    <Grid>
        <MediaElement Name="yourMediaElement">
            <MediaElement.Triggers>
                <EventTrigger RoutedEvent="MediaElement.Loaded">
                     <EventTrigger.Actions>
                         <BeginStoryboard>
                             <Storyboard>
                                 <MediaTimeline Source="http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif"
                             Storyboard.TargetName="yourMediaElement"  
                             RepeatBehavior="Forever" />
                             </Storyboard>
                         </BeginStoryboard>
                     </EventTrigger.Actions>
                 </EventTrigger>
             </MediaElement.Triggers>
         </MediaElement>
     </Grid>
 </Window>

gif ( : http://www.modernathlete.co.za/layout/banners/PEDI_Relax_469x60.gif http://www.gifanimations.com/GA/image/animations/aliens/alien-01.gif), , ( ), , , gif .

- ?

+3
1

MediaElement WPF MediaKit? .

0

Source: https://habr.com/ru/post/1793395/


All Articles