SL Setting Image.Source property to URI
Thursday, March 6, 2008 at 05:51PM Setting the Image.Source property in Silverlight XAML is pretty easy - just like you would think it would work...
<Image Source="/Assets/16_find.png" />
You can even easily bind it to the current data item using the following syntax
<Image Source="{Binding TypeImage}" />
Assuming TypeImage was a valid URI other other valid value
I recently ran into an issue when I wanted to do this in C# and set the value to a string URI.
The first thing I tried was myImage.source = "/Assets/16_find.png";
That generates a compile error because ImageSource isn't compatible with type string.
So how do yo use property to a string URI? You can use the SetValue method as you can see in the following example
imageType.SetValue(Image.SourceProperty,"/Assets/16_find.png");
Reader Comments