![]() 這里主要是以圖片的引用為例。 一、引用同一個程序中的資源 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")); (這三個逗號實際上是三個轉(zhuǎn)義的斜杠。換句話說,上面顯示的包含應用程序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)); |
|