rev*_*kpi 1 c# silverlight silverlight-3.0 silverlight-4.0 windows-phone-7
我看过这篇文章:在Silverlight的WP7应用程序中显示GIF
但就我而言?动画我正在使用弹出窗口.因此,当应用程序启动时,它会显示一个弹出窗口5秒钟.在这个弹出窗口中,我想显示一些.gif图像,但它不起作用.
这是我实现的代码:
public partial class AnimatedSplashScreen : UserControl
{
protected Uri ImageSource
{
get;
set;
}
public AnimatedSplashScreen()
{
InitializeComponent();
ImageSource =
new Uri(
"http://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Sunflower_as_GIF.gif/200px-Sunflower_as_GIF.gif",
UriKind.Absolute);
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
}
Run Code Online (Sandbox Code Playgroud)
而xaml代码是:
<UserControl.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Width="480"
Height="800"
Background="White">
<imagetools:AnimatedImage Source="{Binding ImageSource, Converter={StaticResource ImageConverter}}" />
Run Code Online (Sandbox Code Playgroud)
但结果它不起作用,它显示一个空的背景.
更新:ImageTools.IO.Decoders.AddDecoder(); ImageSource = new Uri(" http://a3.twimg.com/profile_images/1136683647/hisoka_normal.gif ",UriKind.Absolute); 它仍然无法正常工作
最后工作......谈论密谋对你的事件......你需要先解决所有这些问题!
(注意有一个以下问题,只有前两帧被动画,但这是另一个问题):
最后,不支持以"/"开头的相对图像URL ImageTools.Controls.ImageConverter,因此您需要使用不带前导"/"的相对URL.我发现一旦解决了所有其他问题,我就会得到一个不受支持的路径异常.
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
InitializeComponent();
this.ImageSource = new Uri("layer1.gif", UriKind.Relative);
this.DataContext = this;
Run Code Online (Sandbox Code Playgroud)
您需要在某处设置绑定DataContext.
您没有将XAML页面DataContext连接到后面的代码对象.我无法看到你在哪里做到了这一点.一种非常简单/快速的方法是this.DataContext = this;在页面的构造函数中设置.
您只能绑定到公共属性!
您的ImageSource财产目前受到保护.将其更改为Public
public Uri ImageSource
{
get;
set;
}
Run Code Online (Sandbox Code Playgroud)
我还注意到您的ImageSource属性不是INotifyPropertyChange类型属性.因此在InitializeComponent之后设置它将不起作用.
以这种方式尝试(或将其更改为使用notify属性):
public AnimatedSplashScreen()
{
ImageSource =
new Uri(
"/200px-Sunflower_as_GIF.gif",
UriKind.Relative);
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
InitializeComponent();
}
Run Code Online (Sandbox Code Playgroud)
跨域文件显然只是一个问题.根据评论,您还需要将图像存储在您自己的网站上,并使用适当的URI格式引用它们.
如果您将文件放在ClientBin下名为images的文件夹中,则使用以下格式:
"/images/imagename.jpg"
Run Code Online (Sandbox Code Playgroud)
这是最佳选择,因为图像也使用浏览器缓存!
对于你的例子,它将是这样的:
ImageSource =
new Uri(
"/images/200px-Sunflower_as_GIF.gif",
UriKind.Relative);
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
Run Code Online (Sandbox Code Playgroud)
并将示例文件放在图像下的客户端bin文件夹中.
如果你不使用前导"/"Silverlight假定文件是当前模块中的资源,例如
"images/imagename.jpg"
Run Code Online (Sandbox Code Playgroud)
这实际上是一个版权问题,阻止人们在未经许可的情况下深入链接来自其他人网站的文件.
Wikimedia.org网站没有任何跨域访问文件,例如:
...大概是因为他们不希望别人使用他们在自己网站之外托管的文件.
这意味着Silverlight将不允许访问这些网站上的文件,因为它是一个优秀的互联网公民.尝试在您自己的站点(您的Silverlight应用程序所在的位置)托管文件,然后根本不需要任何跨域访问文件.
附注:如果您确实需要在网站上使用跨域文件,供Silverlight使用,请使用crossdomainpolicy.xml,因为另一个文件没有那么有用(专为较旧的Flash使用而设计)
| 归档时间: |
|
| 查看次数: |
2698 次 |
| 最近记录: |