分享

WPF中资源的引用方法

 牛人的尾巴 2016-04-02
标签: wpfpack资源
2015-01-21 18:02 322人阅读 评论(0) 收藏 举报
分类:

这里主要是以图片的引用为例。

一、引用同一个程序中的资源

1、使用相对Uri来引用资源,如下所示

img.Source=new BitmapImage(new Uri(@"d"\iamges\Background\1.jpg"));

使用相对uri: img.Source=new BitmapImage(new Uri("images/1.jpg",UriKind.Relative));

2、使用更累赘的绝对Uri:

img.Source=new BitmapImage(new Uri ("Pack://application:,,,/iamges/1.jpg"));

(这三个逗号实际上是三个转义的斜杠。换句话说,上面显示的包含应用程序URI的Pack URI 是以application:///开头)

二、引用位于其他程序集中的资源

路径的表示方法:Pack://application:,,,/AssemblyName;Component/ResourceName

例如:如果图像被嵌入到一个一引用的名称为ImageLibrary的程序集中,需要使用如下所示的URI:

img.Source=new BitmapImage(newUri(“Pack://application:,,,/ImageLibrary;Component/images/1.jpg"));

或者从更实用的角度,可以使用等价的相对Uri

img.Source =new BitmapImage(new Uri("ImageLibrary;Component/images/1.jpg",UriKind.Relative));

三、使用到了版本号的和公钥标识的强命名程序集

img.Source=new BitmapImage(new Uri("ImageLibrary;v1.25;sd2sw34e432f;Component/Images/1.jpg",UriKind.Relative));

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多