2010-10-20 66 views
0

嘗試顯示圖像時出現圖像問題。 在我的項目中,我有一個女巫有一個「公共字符串圖像」的屬性。 我有一個web服務器本地回來給我一個類的集合。當我在Image atribute中查看調試模式時,它會顯示corect url(如果我在瀏覽器中粘貼url,它會顯示圖像),但圖像不顯示。如果我從互聯網上的圖像中放入任何網址,它會顯示圖像。 我不明白爲什麼本地服務器的圖像沒有在Silverlight應用程序中顯示,但在瀏覽器中顯示。 Silverlight中使用的代碼是:從Silverlight中的服務器發送圖像時出現問題

<Image Name="photoImage" Source="{Binding Image}" Margin="30,10,30,10" /> 

謝謝。

回答

1

嘗試使用該轉換器:

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(); 
    } 
} 
+0

感謝,在另一個地方這個工作稍加修改。 – tribanp 2010-10-21 09:28:44