无法在Silverlight中加载外部图像

时间:2010-09-27 13:31:50

标签: c# silverlight image linker

我正在尝试从Silverlight中的网址加载图片并按照this site中的步骤操作,但无济于事。

我的代码如下:

 imageUri = new Uri("http://php.scripts.psu.edu/dept/iit/hbg/philanthropy/Images/BlueSkyLarge.jpg", UriKind.Absolute);
 System.Windows.Media.Imaging.BitmapImage bi = new    System.Windows.Media.Imaging.BitmapImage();
 bi.UriSource = imageUri;
 m_Image.Source = bi;

 m_Image.ImageOpened += new EventHandler<RoutedEventArgs>(Image_Opened);

永远不会调用回调函数(Image_Opened)..

2 个答案:

答案 0 :(得分:3)

您的Silverlight应用程序是否从域php.scripts.psu.edu运行?如果没有,Silverlight将阻止对它的访问,因为它不允许对除加载应用程序之外的任何域发出TCP请求。

有关Silverlight中的网络限制,请参阅here

编辑:评论者是对的。这是你现在看到的跨区域问题。 Here's a link带有一个表格,表明图像(以及其他图像)可以做什么和不能做什么。

答案 1 :(得分:-1)

我在代码中修复的另一件事是你在最后附加处理程序。 理论上,如果图像真正快速加载,则可能无法调用事件处理程序。

我认为在大多数情况下不会发生这种情况,而是使用缓存/对象重用/等。谁知道。我会在实例化对象之后附加处理程序并且是安全的。

相关问题