zoukankan      html  css  js  c++  java
  • WPF中资源的引用方法

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

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

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

  • 相关阅读:
    9.17考试
    Something
    tesuto-Mobius
    7.22考试
    填坑...P1546 最短网络 Agri-Net
    P1125 笨小猴
    P2822 组合数问题
    致我们曾经刷过的水题
    Luogu P1186 玛丽卡
    Luogu P1726 上白泽慧音
  • 原文地址:https://www.cnblogs.com/qianyaoyuan/p/3022810.html
Copyright © 2011-2022 走看看