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));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM