• Uri(uniform resource identifiers)的用法


    Uri(uniform resource identifiers)

    通过它可以在程序的执行过程中,加载file, image等。

    Uri有两种类型,绝对路径和相对路径,下面是两种类型的写法:

    注意component是关键字。

    Table 3: Absolute Pack URIs in Code

    File

    Absolute pack URI

    Resource file - local assembly

    Uri uri = new Uri("pack://application:,,,/ResourceFile.xaml", UriKind.Absolute);

    Resource file in subfolder - local assembly

    Uri uri = new Uri("pack://application:,,,/Subfolder/ResourceFile.xaml", UriKind.Absolute);

    Resource file - referenced assembly

    Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml", UriKind.Absolute);

    Resource file in subfolder of referenced assembly

    Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml", UriKind.Absolute);

    Resource file in versioned referenced assembly

    Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;v1.0.0.0;component/ResourceFile.xaml", UriKind.Absolute);

    Content file

    Uri uri = new Uri("pack://application:,,,/ContentFile.xaml", UriKind.Absolute);

    Content file in subfolder

    Uri uri = new Uri("pack://application:,,,/Subfolder/ContentFile.xaml", UriKind.Absolute);

    Site of origin file

    Uri uri = new Uri("pack://siteoforigin:,,,/SOOFile.xaml", UriKind.Absolute);

    Site of origin file in subfolder

    Uri uri = new Uri("pack://siteoforigin:,,,/Subfolder/SOOFile.xaml", UriKind.Absolute);

    Table 4 illustrates the various relative pack URIs that you can specify in code using System..::.Uri.

    Table 4: Relative Pack URIs in Code

    File

    Relative pack URI

    Resource file - local assembly

    Uri uri = new Uri("/ResourceFile.xaml", UriKind.Relative);

    Resource file in subfolder - local assembly

    Uri uri = new Uri("/Subfolder/ResourceFile.xaml", UriKind.Relative);

    Resource file - referenced assembly

    Uri uri = new Uri("/ReferencedAssembly;component/ResourceFile.xaml", UriKind.Relative);

    Resource file in subfolder - referenced assembly

    Uri uri = new Uri("/ReferencedAssembly;component/Subfolder/ResourceFile.xaml", UriKind.Relative);

    Content file

    Uri uri = new Uri("/ContentFile.xaml", UriKind.Relative);

    Content file in subfolder

    Uri uri = new Uri("/Subfolder/ContentFile.xaml", UriKind.Relative);

     

    对于absolute Uri, 我们可以用Application.LoadComponent(resourceUri)方法读取

    load的对象,返回值是一个object

    对于relative Uri,Application.GetResourceStream(resourceUri) 方法读取

    load的对象,返回值是一个Stream。对于xaml文件,就可以用XmlDocument读取这个

    Stream了:

    XmlDocument theXmlDocument = new XmlDocument();

                            theXmlDocument.Load(Stream);

  • 相关阅读:
    SpringMVC---RequestMapping注解类的使用方法
    SpringMVC---简单登录例子
    SpringMVC---简介
    MyBatis---动态SQL
    Hive基本操作
    hive初识
    scala编码规范
    Spark2.x 与 Spark1.x 关系
    spark idea项目打jar包的两种方式
    SparkStreaming 对Window的reduce的方法解析(转载)
  • 原文地址:https://www.cnblogs.com/bear831204/p/1305564.html
Copyright © 2020-2023  润新知