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

  • 相关阅读:
    Steps to Writing Well----Reading Notes
    How to Improve Reading Skills
    Requirement-Driven Linux Shell Programming
    Linux tar command usage
    MVC和MVVM模型
    js中特殊的宏任务
    js 超浓缩 双向绑定
    JavaScript 中的遍历详解
    多段动画整合为一个动画的思路
    Js事件循环(Event Loop)机制
  • 原文地址:https://www.cnblogs.com/zerommc/p/11598336.html
Copyright © 2011-2022 走看看