使用 MediaElement 的 WPF 动画 GIF [英] WPF animated GIF using MediaElement
问题描述
我需要一个旋转加载器来显示我的应用程序何时忙.
我发现一些帖子表明 MediaElement 是最好的方法.我有以下在设计器上显示 ajax-loader.gif 的内容.但是,当我运行应用程序时,MediaElement 没有显示任何内容.
<MediaElement Source="file:images/ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible"/>
并且不确定这是否是相关问题,但从设计者的角度来看,Source 下拉列表没有选择我的图像(Build Action = Resource for them).所以我手动指定了允许它在设计器中显示的文件.但是,在运行时,图像消失了.
如果我在静态位置指定图像,它在设计和运行时都有效.
<块引用>C:\temp\ajax-loader.gif
<MediaElement Source="file:/temp/ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible"/>
很明显,即使我认为我的图像具有 Build Action = Resource,它们也没有被 MediaElement 接收.我什至尝试过简单...
<MediaElement Source="ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible"/>
如何使用 MediaElement 显示作为资源加载的动画 GIF?
事实证明 MediaElement Source 属性无法根据本文拉取资源...
我的解决方案是...
<MediaElement Source="Images/ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible"/>
并设置 Build Action = Content...
I need to get a spinning loader to show when my application is busy.
I found a few posts suggesting the MediaElement is the best way to go. I have the following that displays the ajax-loader.gif on the designer. However, when I run the application, the MediaElement doesn't show anything.
<MediaElement Source="file:images/ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible" />
And not sure if this is a related problem, but from the designer, the Source dropdown isn't picking up my images (Build Action = Resource for them). So I manually specified the file which allows it to show in the designer. However, at runtime, the image disappears.
If I specify the image in a static location it works in design and runtime.
C:\temp\ajax-loader.gif
<MediaElement Source="file:/temp/ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible" />
So clearly, even thought I have the Build Action = Resource for my images, they are not getting picked up by the MediaElement. I even tried simply...
<MediaElement Source="ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible" />
How can I use a MediaElement to show an animated GIF that is loaded as a Resource?
It turns out MediaElement Source property can't pull a Resource per this article...
https://msdn.microsoft.com/es-es/library/aa970915(v=vs.85).aspx
My solution is...
<MediaElement Source="Images/ajax-loader.gif" LoadedBehavior="Play" Visibility="Visible" />
And set the Build Action = Content...
这篇关于使用 MediaElement 的 WPF 动画 GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!