![]() 這里主要是以圖片的引用為例。 一、引用同一個(gè)程序中的資源 1、使用相對(duì)Uri來(lái)引用資源,如下所示 img.Source=new BitmapImage(new Uri(@"d"\iamges\Background\1.jpg")); 使用相對(duì)uri: img.Source=new BitmapImage(new Uri("images/1.jpg",UriKind.Relative)); 2、使用更累贅的絕對(duì)Uri: img.Source=new BitmapImage(new Uri ("Pack://application:,,,/iamges/1.jpg")); (這三個(gè)逗號(hào)實(shí)際上是三個(gè)轉(zhuǎn)義的斜杠。換句話說(shuō),上面顯示的包含應(yīng)用程序URI的Pack URI 是以application:///開(kāi)頭) 二、引用位于其他程序集中的資源 路徑的表示方法:Pack://application:,,,/AssemblyName;Component/ResourceName 例如:如果圖像被嵌入到一個(gè)一引用的名稱為ImageLibrary的程序集中,需要使用如下所示的URI: img.Source=new BitmapImage(newUri(“Pack://application:,,,/ImageLibrary;Component/images/1.jpg")); 或者從更實(shí)用的角度,可以使用等價(jià)的相對(duì)Uri img.Source =new BitmapImage(new Uri("ImageLibrary;Component/images/1.jpg",UriKind.Relative)); 三、使用到了版本號(hào)的和公鑰標(biāo)識(shí)的強(qiáng)命名程序集 img.Source=new BitmapImage(new Uri("ImageLibrary;v1.25;sd2sw34e432f;Component/Images/1.jpg",UriKind.Relative)); |
|