2013-04-10 39 views
0

我按照這篇文章(http://mikaelkoskinen.net/winrt-step-by-step-tutorial-mvvm-gridview-semanticzoom/)逐步添加圖像到我的項目的GridView,但是當我完成添加GridView到我的項目後面這篇文章。我在展示圖片時遇到了問題,圖片(在項目文件夾中)在應用程序運行時不顯示,但應用程序顯示來自Internet的圖像(文章中的代碼運行良好並從項目文件夾加載圖像),我不知道如何表達這個問題,在GridView上顯示圖像贏8地鐵風格?

這是一些代碼:

public class Movie 
{ 
    public string Title { get; set; } 
    public string Subtitle { get; set; } 
    public string Image { get; set; } 
    public string Category { get; set; } 
} 

public class MovieCategory 
{ 
    public string Title { get; set; } 
    public List<Movie> Items { get; set; } 
} 

我的代碼從項目文件夾中加載圖像:

MovieList.Add(new Movie { Title = "The Ewok Adventure", Category = "Adventure", Subtitle = "The Towani family civilian shuttlecraft crashes on the forest moon of Endor.", Image = "duy.jpg" }); 

(我以前創建MovieList和圖像「duy.jpg」是該項目的文件夾中)我爲什麼我不試試上面的代碼源從文章

,我通過調試工具仔細檢查圖像源字符串,它運行良好(來自項目文件夾的圖像顯示在文章的源文件中),但是當我添加到我的項目時,來自Internet鏈接的圖像運行良好,但來自項目文件夾的圖像未加載。 請幫助我,感謝您的提前。

回答

0

更改類的定義是這樣

public class Movie 
{ 
    public string Title { get; set; } 
    public string Subtitle { get; set; } 
    public string Image { get; set; } 
    public string Category { get; set; } 

    public ImageSource ImgSource 
    { 
     get 
     { 
      return new BitmapImage(new Uri("ms-appx:///" + this.Image)); 
     } 
    } 
} 

並結合圖片標籤與ImgSource財產不是財產Image

<Image Source="{Binding ImgSource}" ........./> 
+0

謝謝,我已經展示了這個問題 – 2013-04-10 16:53:35

0

是項目根目錄中的圖像?你是否設置爲內容並始終複製到輸出文件夾?

+0

來自根文件夾的圖像,我已經將Build Action設置爲內容並始終複製到輸出文件夾,但沒有任何更改。它無法加載根文件夾中的圖像。文章中的源代碼與根文件夾中的圖像效果很好。 – 2013-04-10 11:04:29