如何在WP 7中使用gif动画图像

我看过这篇文章: 在Silverlight的WP7应用程序中显示GIF

但就我而言? 动画我正在使用弹出窗口。 因此,当应用程序启动时,它会显示一个弹出窗口5秒钟。 在这个弹出窗口中,我想显示一些.gif图像,但它不起作用。

这是我实现的代码:

public partial class AnimatedSplashScreen : UserControl { protected Uri ImageSource { get; set; } public AnimatedSplashScreen() { InitializeComponent(); ImageSource = new Uri( "http://sofzh.miximages.com/c%23/Sunflower_as_GIF.gif/200px-Sunflower_as_GIF.gif", UriKind.Absolute); ImageTools.IO.Decoders.AddDecoder(); } 

而xaml代码是:

      

但结果它不起作用,它显示一个空的背景。

更新:ImageTools.IO.Decoders.AddDecoder(); ImageSource = new Uri(“ http://sofzh.miximages.com/c%23/hisoka_normal.gif ”,UriKind.Absolute); 它仍然无法正常工作

最后工作……谈论密谋反对你的事件……你需要先解决所有这些问题!

(注意,只有前2帧被动画,但这是另一个问题)存在以下问题

第6部分(现在昏昏欲睡)

最后, ImageTools.Controls.ImageConverter不支持以“/”开头的相对图像URL,因此您需要使用不带前导“/”的相对URL。 我发现一旦解决了所有其他问题,我就会得到一个不受支持的路径exception。

  ImageTools.IO.Decoders.AddDecoder(); InitializeComponent(); this.ImageSource = new Uri("layer1.gif", UriKind.Relative); this.DataContext = this; 

第5部分

您需要在某处设置绑定DataContext。

您没有将XAML页面DataContext连接到后面的代码对象。 我无法看到你在哪里做到了这一点。 一个非常简单/快速的方法是设置this.DataContext = this; 在页面的构造函数中。

第4部分

您只能绑定到公共属性!

您的ImageSource属性当前受到保护。 将其更改为Public

  public Uri ImageSource { get; set; } 

第3部分

我还注意到您的ImageSource属性不是INotifyPropertyChange类型属性。 因此在InitializeComponent之后设置它将不起作用。

以这种方式尝试(或将其更改为使用notify属性):

 public AnimatedSplashScreen() { ImageSource = new Uri( "/200px-Sunflower_as_GIF.gif", UriKind.Relative); ImageTools.IO.Decoders.AddDecoder(); InitializeComponent(); } 

第2部分(实际上不支持ImageTools.Controls.ImageConverter)

跨域文件显然只是一个问题。 根据评论,您还需要将图像存储在您自己的网站上,并使用适当的URI格式引用它们。

如果您将文件放在ClientBin下名为images的文件夹中,则使用以下格式:

 "/images/imagename.jpg" 

这是最好的选择,因为图像也使用浏览器缓存!

对于你的例子,它将是这样的:

  ImageSource = new Uri( "/images/200px-Sunflower_as_GIF.gif", UriKind.Relative); ImageTools.IO.Decoders.AddDecoder(); 

并将示例文件放在图像下的客户端bin文件夹中。

如果你不使用前导“/”Silverlight假定文件是当前模块中的资源,例如

 "images/imagename.jpg" 

第1部分

这实际上是一个版权问题,阻止人们在未经许可的情况下从其他人的网站深层链接文件。

Wikimedia.org网站没有任何跨域访问文件,例如:

…大概是因为他们不希望别人使用他们在自己网站之外托管的文件。

这意味着Silverlight将不允许访问这些网站上的文件,因为它是一个优秀的互联网公民 。 尝试在您自己的站点(您的Silverlight应用程序所在的位置)托管文件,然后根本不需要任何跨域访问文件。

附注:如果您确实需要网站上的跨域文件,供Silverlight使用,请使用crossdomainpolicy.xml,因为另一个文件没有用(专为较旧的Flash使用而设计)