2015-06-18 28 views
2

我試圖定義來源爲我在Windows通用應用的圖像,但它GIVS我以下錯誤:C# - 通用的Windows應用程序 - 圖像源不起作用

Invalid URI: The format of the URI could not be determined.

imagePath = "Assets/Category-other-dark.png"; 
Uri uri = new Uri(imagePath, UriKind.Absolute); 
ImageSource imgSource = new BitmapImage(uri); 
imgCategory.Source = imgSource; 

我通過搜索許多論壇和嘗試了很多東西,但沒有任何工作。謝謝。

+0

我想什麼寫了文章。 –

+0

你的png位置在哪裏?應用包或應用數據? –

回答

6

將其更改爲:

imagePath = "ms-appx:///Assets/Category-other-dark.png"; 
Uri uri = new Uri(imagePath, UriKind.RelativeOrAbsolute); 
ImageSource imgSource = new BitmapImage(uri); 
imgCategory.Source = imgSource; 
+0

我試過了,但是......'給定的System.Uri不能轉換成Windows.Foundation.Uri。' –

+0

@JanChalupa現在嘗試 – Jyrka98

+0

行,行得通,我的錯。謝謝! –

0

試試這個

imagePath = "Assets/Category-other-dark.png"; 
    Uri uri = new Uri(imagePath, UriKind.RelativeOrAbsolute); 
    ImageSource imgSource = new BitmapImage(uri); 
    imgCategory.Source = imgSource; 
+0

我試過了,但是......'給定的System.Uri不能轉換成Windows.Foundation.Uri。' –

+0

導入時檢查導入的包名稱。導入System.Uri而不是Windows.Foundation.Uri – Mathivanan

+0

導入什麼?我不明白。請原諒我的知識和糟糕的英語。 :) –

0

必須使用本地,漫遊或溫度:

var uri = new System.Uri("ms-appdata:///local/Assets/logo.png"); 
相關問題