I have a problem with a image when trying to display it.
In my project i have a Class witch have a “public String Image” atribute.
I have a web server localy wich return me a colection of Class. When i look in debug mode at the Image atribute it show me the corect url (if i paste the url in browser it show me the image) but the image isn’t display. If instead i put any url from an image from internet it show me the image.
I don`t understand why the image from local server isn’t shown in silverlight app, but in browser it is.
The code used in Silverlight is:
<Image Name="photoImage" Source="{Binding Image}" Margin="30,10,30,10" />
Thanks.
,
Try using this converter:
public class RelativeImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) { return null; }
var originalString = value.ToString();
if (!Uri.IsWellFormedUriString(originalString, UriKind.RelativeOrAbsolute)) { return null; }
var imageUri = new Uri(originalString, UriKind.RelativeOrAbsolute);
if (!imageUri.IsAbsoluteUri)
{
var hostUri = Application.Current.Host.Source;
imageUri = new Uri(hostUri, originalString);
}
var image = new BitmapImage(imageUri);
return image;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}