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
2009-02-23 12:44:04
Doesnt accept string i meant for example: MyImage.Source = "/MyNameSpace;images/someimage.png" like in asp.net
Drahcir
2009-02-23 13:47:22
ah, needed that!
Michel
2010-04-08 19:01:14
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
2010-10-04 08:13:07