tags:

views:

6196

answers:

2

I am dynamically generating an image through code behind in Silverlight and apparently the image source doesnt accept string nor Uri as a path. How can I set the source?

+10  A: 

How do you mean it won't accept a string as source?

Are you not able to do this?

Or are you saying your image is in memory and you don't know how to reference it?

this.MyImage.Source = new BitmapImage(new Uri("/MyNameSpace;images/someimage.png", UriKind.Relative));
Gautam
Doesnt accept string i meant for example: MyImage.Source = "/MyNameSpace;images/someimage.png" like in asp.net
Drahcir
ah, needed that!
Michel
A: 
// create a new image
Image image = new Image();

// better to keep this in a global config singleton
string hostName = Application.Current.Host.Source.Host;                   
if (Application.Current.Host.Source.Port != 80)
    hostName += ":" + Application.Current.Host.Source.Port;

// set the image source
image.Source = new BitmapImage(new Uri("http://" + hostName + "/sexy_lesbians112.jpg", UriKind.Absolute));  
Malcolm Swaine