locked
Understanding 2.0 RRS feed

  • Question

  •  I just downloaded Silverlight 2.0 tools for VS 2008 and created a Silverlight application. It created a Solution and added two projects to it. A Silverlight  project and a website for testing. Next I wanted to load an image in my Silverlight project from my website (or from any other places on my PC). How would I do it? It only works if I add the image to the Silverlight project.

    Saturday, March 8, 2008 9:13 PM

Answers

  • You can get the absolute URL programmatically:

    string url = App.Current.Host.Source.AbsoluteUri;

    int index = url.IndexOf("/ClientBin");

    url = url.Substring(0, index) + "/image.jpg;

     

    You can have multiple xap files. But this will require multiple Silverlight projects.

    Tuesday, March 11, 2008 10:38 PM

All replies

  • You can use any image on the web, check my blog for details.

    Sunday, March 9, 2008 8:09 AM
  •  Thx. I will.

    I am trying to understand the relationship between two projects (Silverlight and website). If I add a website to the solution, do I need to link it to Silverlight project? I yes, how? Also, while building, does it just create one big .xap file? If yes,  won't it be a big file to FTP? Also, does it need to download the entire .xap file into the client's browser before running it?

    Sunday, March 9, 2008 2:22 PM
  • If you want to reference images by absolute URL, add them to the _web website. If you want to include images embedded in your Xap, add them to the Silverlight project.

    Adding some images to your xap makes sense when the app won't make sense without those images (for example, buttons, branding graphics etc.). Images that can be lazy-loaded should typically be stored on teh site.

    Pete

    Sunday, March 9, 2008 8:35 PM
  • There are a couple of issues here.

    I have a Solution that has a Silverlight project as well as a test website. I have my image in the test website (and not in Silverlight project). So when I am designing a xaml page, I somehow need to tell to look at the other project - so that in design mode, the image shows up. When I build the project, since the xap file is placed in a folder in website (and not in Silverlight project), it needs to pickup the image from the website. I tried absolute url like http://localhost/image.jpg for the source. No luck. It only works if I place the image in the same folder (or subfolder) as xap file and do source="image.jpg"

    Also, it seems to create a single xap file. Does the full xap file need to be downloaded in the client browser before running? 

    Sunday, March 9, 2008 9:01 PM
  • Hello, absolute url should work. Are you sure you write the correct url? One thing to check is the point number. Unless you're using the default 80, you should include the point number in the url. Also check the path. For example, a correct url maybe: http://localhost:11111/yourwebsite/image.jpg

    For your second question, yes, the xap file must be downloaded first before running. If you're concerned about the size of the xap file, you can also use on demand deployment as described here. (See the "On-Demand Deployment for Library Assemblies" section.)

    Tuesday, March 11, 2008 3:29 AM
  •  If I have to use absolute URL, I don't know the port number on the DEV box as it it randomly assigned. And when I am ready to move it to TST box, the port number is not used at all.

     For the second part, is it possiblle to have multiple XAP files (one for each XAML files) ?
     

    Tuesday, March 11, 2008 12:25 PM
  • You can get the absolute URL programmatically:

    string url = App.Current.Host.Source.AbsoluteUri;

    int index = url.IndexOf("/ClientBin");

    url = url.Substring(0, index) + "/image.jpg;

     

    You can have multiple xap files. But this will require multiple Silverlight projects.

    Tuesday, March 11, 2008 10:38 PM