如何在 WPF 中连续播放 .gif 文件 [英] How a continuous play .gif file in WPF
本文介绍了如何在 WPF 中连续播放 .gif 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件格式 gif 我把它放在 mediaelement 中,动画有效,但如何使该文件连续播放
I have a file format gif I put it in mediaelement, animation worked, but how to make that file was played continuously
推荐答案
您可以使用 MediaTimeline 元素使动画永远循环:
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>
上述解决方案似乎不适用于大小超过几千字节的 GIF 文件.这个问题显然来自 Windows Media Player(它可以用 WMP 本身重现).所以,YMMV.
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.
这篇关于如何在 WPF 中连续播放 .gif 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文