zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    移动端触摸右侧菜单栏,页面内容对应项滚动到最上方
    swiper使用中一些点的总结
    javaScript正则表达式入门
    javaScript之数组操作方法(一)
    初识vue
    焦点控制切换和轮播
    文本内容只显示两行,然后加...
    图片父容器高度不定的图片垂直居中
    css3图片垂直居中
    【C#】两个list根据某个元素比较差集
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2457989.html
Copyright © 2011-2022 走看看