As a continuous .gif file for playback in WPF

I have a gif file format I put it in mediaelement, the animation worked, but how to make this file play continuously

+3
source share
1 answer

You can use the MediaTimeline element to create an animation loop forever:

<MediaElement Name="yourMediaElement">
    <MediaElement.Triggers>
        <EventTrigger RoutedEvent="MediaElement.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <MediaTimeline Source="YourAnimation.gif"
                            Storyboard.TargetName="yourMediaElement"  
                            RepeatBehavior="Forever" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </MediaElement.Triggers>
</MediaElement>

EDIT: The solution above does not work with GIF files that are larger than a few kilobytes. The problem seems to come from Windows Media Player (it can be played using WMP itself). So, YMMV.

+1
source

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


All Articles