How a continuous play .gif file in WPF

后端 未结 1 1884
一整个雨季
一整个雨季 2021-01-20 13:21

I have a file format gif I put it in mediaelement, animation worked, but how to make that file was played continuously

相关标签:
1条回答
  • 2021-01-20 14:05

    You can use a MediaTimeline element to make the 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 seem to be working with GIF files whose size exceeds a few kilobytes. The issue apparently come from Windows Media Player (it can be reproduced with WMP itself). So, YMMV.

    0 讨论(0)
提交回复
热议问题