wp7資源調用

有一個朋友問過我這樣一個問題,他在應用程序中調用圖片卻不顯示。下面介紹一下資源之間的調用以及關係。

image項目的結構,在Images的文件夾裏有兩張圖片。

imageimageflash圖片的生成操作爲Resource,ps圖片的生成操作爲內容。

 

編譯打包之後生成的結構如下圖。

imageimageImages文件夾裏面只有ps圖片,因爲ps圖片的生成操作爲內容。

程序中的其他資源在ResDemo.dll中。

image頁面文件以及生成操作爲Resource的flash圖片都都打包到ResDemo.dll中了,結構如上圖。

下面我們就開始調用

image6張圖片,左邊豎着數分別爲image1、Image2、image3。右邊豎着數分別爲image4、image5、image6。

佈局代碼如下:

   1:  <Grid x:Name="ContentPanel" Margin="12,0,12,0">
   2:       <Image Height="200" HorizontalAlignment="Left" Margin="9,21,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/ResDemo;component/Images/flash.png" />
   3:       <Image Height="200" HorizontalAlignment="Left" Margin="9,247,0,0" Name="image2" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="Images/flash.png" />
   4:       <Image Height="200" HorizontalAlignment="Left" Margin="9,482,0,0" Name="image3" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/Images/ps.png" />
   5:       <Image Height="200" HorizontalAlignment="Left" Margin="231,21,0,0" Name="image4" Stretch="Fill" VerticalAlignment="Top" Width="200" />
   6:       <Image Height="200" HorizontalAlignment="Left" Margin="231,247,0,0" Name="image5" Stretch="Fill" VerticalAlignment="Top" Width="200" />
   7:       <Image Height="200" HorizontalAlignment="Left" Margin="231,482,0,0" Name="image6" Stretch="Fill" VerticalAlignment="Top" Width="200" />
   8:</Grid>

image1通過"/ResDemo;component/Images/flash.png"訪問Resource資源的flash圖片。

因爲xaml頁面也是Resource,所以也可以通過相對路徑Images/flash.png來調用flash圖片。

ps圖片是內容,所以以文件形式存放在ResDemo.dll,用"/Images/ps.png調用。

下面三個圖片爲後臺代碼賦值。(路徑跟xaml頁面一樣)

   1:   image4.Source = new BitmapImage(new Uri("/ResDemo;component/Images/flash.png", UriKind.RelativeOrAbsolute));
   2:   image5.Source = new BitmapImage(new Uri("Images/flash.png", UriKind.RelativeOrAbsolute));
   3:   image6.Source = new BitmapImage(new Uri("/Images/ps.png", UriKind.RelativeOrAbsolute));
文章源地址:http://www.cnblogs.com/wildfeng/archive/2012/04/03/2430599.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章