1、引用同一個程序中的資源app
一、使用相對Uri來引用資源,以下所示資源
img.Source=new BitmapImage(new Uri(@"d"\iamges\Background\1.jpg"));it
使用相對uri: img.Source=new BitmapImage(new Uri("images/1.jpg",UriKind.Relative));io
二、使用更累贅的絕對Uri:map
img.Source=new BitmapImage(new Uri ("Pack://application:,,,/iamges/1.jpg"));引用
(這三個逗號其實是三個轉義的斜槓。換句話說,上面顯示的包含應用程序URI的Pack URI 是以application:///開頭)程序
2、引用位於其餘程序集中的資源方法
路徑的表示方法:Pack://application:,,,/AssemblyName;Component/ResourceNameim
例如:若是圖像被嵌入到一個一引用的名稱爲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));
3、使用到了版本號的和公鑰標識的強命名程序集
img.Source=new BitmapImage(new Uri("ImageLibrary;v1.25;sd2sw34e432f;Component/Images/1.jpg",UriKind.Relative));