RPM: Pack URI in WPF

Source: Internet
Author: User

At first you see WPF often constructs a resource file URI with the following statement:

Uri uri = new Uri ("/assemblyname;component/image.png");

I thought the string in this format was a URI standard, but I looked it up on the web and didn't find a URI string in this format.

The URI is a uniform resource identifier, and the general syntax is:

Protocol name (Http,https,ftp,file, etc.) + colon + content corresponding to the protocol

URIs are also categorized as URLs and Urn,url are used to define access paths for a resource. A urn is a name that defines a resource. (http://zh.wikipedia.org/zh/Uniform Resource Identifier)

Take a closer look at MSDN before discovering that the string in the format above is a URI format that the software itself extends, the pack URI. This URI is used very much in WPF and is used primarily to locate

Resource files, as well as XAML files.

The Pack URI is primarily used to describe the constituent units contained in a package.

1. Main grammar of Pack URI

Pack://authority/path

Where authority refers to the type of package referred to here, and path mainly refers to the constituent units referred to here in the package path.

The authority supported by WPF include: application:///and siteoforigin:///:

The former is mainly used to describe the resources that are known at the time of Yi (e.g., resource files, etc., files referenced by project are known at Yi Time),

The latter is used primarily to describe external resources (such as a file on a hard disk or a file on a grid) that cannot be determined at Yi.

Note: When you actually build the pack URI, you need to replace the "/" in the Authority with ",". So application:///should be for application:,,,, siteoforigin:///analogy.

2. Usage of Pack URIs

(1) When representing the resource referenced in the current assembly, build the pack URI in the following format

Pack://application:,,,/(relative path of the resource relative to the directory where the Assembly resides)

(2) When the resource referenced by other assembly referenced by the current assemby is represented, the pack URI is constructed in the following format

Pack://application:,,,/assemblyshortname[; version][; publickey];component/(relative path of the resource relative to the directory where the assembly resides)

(3) When representing a resource of type Siteoforigin, build the pack URI in the following format

Pack://siteoforigin:,,,/(the path of the resource relative to the location of the currently executing assembly)

3. Absolute Pack URI and relative pack URI

All of the above are absolute pack URIs, and the format contains Schema://authority/path. Strings are long and not very convenient to write.

So there is also a simplified version of the relative pack URI, which is constructed using path only.

Note: When representing the resource referenced in the current assembly, path represents the relative path of the target resource relative to the current path. Add "/" to the path to indicate the root directory relative to the assembly

https://msdn.microsoft.com/library/aa970069 (v=vs.100). aspx

RPM: Pack URI in WPF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.