2010-03-22 58 views
2

在SL類庫MyLib中,我有一個圖像說my.png。然後我想在後面的代碼中使用它我試着按照下面的方式:如何在silverlight應用程序中爲本地圖像設置uri?

StreamResourceInfo resourceStream = Application.GetResourceStream(new Uri("/MyLib;component/my.png", UriKind.Relative));  
BitmapImage image = new BitmapImage();         
image.SetSource(resourceStream.Stream); 
this.MyIcon.Source = image; 

但它不是在開火。我認爲這是Uri設置不正確。請幫助。

回答

0

您是否在屬性窗口或「內容」中將圖像標記爲「資源」?

0

你總是可以設置一個風格在你的應用程序中的資源,然後把它想:

Application.Current.Resources [「myCoolStyle」]並應用到圖像。

1

這工作: -

BitmapImage image = new BitmapImage(new Uri("/MyLib;component/my.png", UriKind.Relative)); 
MyIcon.Source = image; 

我不明白你爲什麼會想在這裏使用一個Stream。說了你的流代碼應該工作。對於png的構建操作應該是Uri中的「Resource」和「MyLib」,應該是項目屬性的「Silverlight」選項卡上找到的庫的程序集名稱。

相關問題