2014-06-24 60 views
0

我應該得到我的圖像的Uri,但是當我嘗試這樣做時,會出現此錯誤。在Windows Phone中獲取圖像的Uri

Quick Watch

圖像的UriSource能夠鑄造的BitmapImage但BitmapImage的屬性都扔錯誤。我如何獲取圖片的來源?

img0.Source = GetImageForIndex(0, names, file, path).ImgSource; 

ImageListTemplate GetImageForIndex(int index, List<string> names, IsolatedStorageFile file, string path) 
    { 
     using (IsolatedStorageFileStream stream = file.OpenFile(path + names[index], FileMode.Open, FileAccess.Read)) 
     { 
      BitmapImage tempImage = new BitmapImage(); 
      tempImage.SetSource(stream); 
      imagePath = path + names[index]; 
      return new ImageListTemplate() { ImgSource = tempImage }; 
     } 
    } 

ImgSource的類型已經是BitmapImage了。

回答

2

您沒有爲圖像設置URI源,而是從數據流中加載它。可以從流或URI填充BitmapImage。您只能通過從URI創建圖像來讀取UriSource(如果已設置)。

根據您的代碼,如果您想在查詢SelectedItem時想返回原始數據源的參考,我建議將該路徑/文件信息存儲在Tag屬性中。或者將其添加爲綁定項目數據源的另一個屬性並查詢該屬性。

+0

我已經做了它,我問它作爲你的答案。謝謝。 –

相關問題