views:

1134

answers:

5

I'm trying to display an image within a Silverlight application but the image does not display when the application is run. When creating the project within Visual Studio I chose the "Automatically generate a test page to host Silverlight at build time" option.

Complete code as an example:

<UserControl x:Class="SilverlightApplication3.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <StackPanel>        
        <Image Source="http://www.beachtownpress.com/db5/00415/beachtownpress.com/_uimages/beach7.jpg" />
    </StackPanel>
</UserControl>

The application appears perfectly within Visual Studio, but when I run the application, the image does not display. Any ideas?

+1  A: 

Mmm...

Take a look to this doc:

http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source(VS.95).aspx

I think the main issue is that you are making a cross domain call, just and advice: download fiddler, there you will check if the server where you are requesting the data allows cross domain calls (just give a try, load an image from flckr and see what happens).

One solution, could be to use tunneling on the server side (a custom http hanlder on your domain, that grabs the image from a remote server and redirects it to your SL petition).

HTH Braulio

Braulio
A: 

Your example is absolutely working. I've just tried it.

May be the problem is in the network?

You can debug network communications via Fiddler.

Alexander K.
A: 

While cross-domain URL access is allowed for the Image control, cross-scheme access is not. When running using the automatically generated test page, it will run from your local drive (I guess that would indirectly run in under the FILE protocol), so it will not be allowed to cross-scheme to the HTTP protocol. What you should do is to have the page containing your Silverlight control run under http://localhost, that should do the trick.

Reference: URL Access Restrictions in Silverlight

p/s: I know this answer came in a bit too late, but since I happened to stumbled this same issue just a moment ago (just started playing with Silverlight for the first time), I thought I would just answer this question.

Amry
A: 

Wow .. this is a real show stopper... I'm a WPF developer and I've been doing this for years no problem. I can't believe MS would build a Web platform that does not allow the loading of images off the web. It's even more ridiculous that I can see the image I'm trying to load at design time, but as soon as I run the app, it gets blocked. So frustrating!!

Sam
A: 

I have the exact same problem. It freaked me out when I ran the application from EXPRESSION BLEND 3, but it doesn't WORK from VS 2008 .... I'm looking for the answer right now ....

~~~EDIT~~~~ I found the solution. Simply go to the Solution and ADD a new ASP.NET Web application ... It should work... It did for me ...

Cosmin