tags:

views:

16

answers:

2

I'm trying to use the Image control is a very basic way, like here:

http://www.silverlightshow.net/items/Using-the-Image-control-in-Silverlight-2-Beta-1.aspx

So I'm ending up with XAML like this:

<Image x:Name="imgSmall" Stretch="Fill" Source="../Img/Small/105.jpg" Margin="10,0,0,0"></Image> 

Which isn't working. The Image is blank, and in the designer the URI is underlined with a message of "...is not part of the project or its build action is not set to 'Resource"

If I change the source to a property on my ViewModel, set like this:

new Uri(App.Current.Host.Source, "../Img/Small/105.jpg");

Then it works fine. I'd much prefer to use the simpler syntax and get the image directly. Is this possible?

(The images are one level up from ClientBin)

Setting all of my web sites images to build=Resource is not possible.

Thanks!

A: 

It id doesn't work because image is not added to your project. Add image to project and in then you can set source from xaml.

Samvel Siradeghyan
+1  A: 

You have to create a converter that takes the relative image path and adds the "absolute" part. You can pass the relative Uri as binding value or as converterParameter.

class ImageConverter : IValueConverter
{
    // method convert()
    return new BitmapImage(new Uri(App.Current.Host.Source, ((string)parameter));
    //...
}
Francesco De Vittori