WPF中资源的引用方法

南笙酒味 提交于 2019-12-09 04:29:07

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

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

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

 

posted on 2013-04-15 20:34 LearnerYQY 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/qianyaoyuan/archive/2013/04/15/3022810.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!