WPF Learning Notes

Source: Internet
Author: User
Tags pack resource

1. Binary resources WPF supports three binary resources, which can be easily used in XAML.

Resource: Embedding resources in assemblies is a bit like Embedded Resource. The difference is that WPF packages related resources to. Resources file, which is then embedded in the assembly file by the compiler. The WPF default URI access method does not support Embedded Resource.

Content: Resources are not embedded in the assembly, just adding a record to the assembly manifest is the same way as we used to know. Resource files must be deployed with other assembly files to the destination directory.

Loose File: This type of resource is usually dynamically determined or joined during runtime.

WPF accesses related resource files through a Uniform Resource Identifier (URI).

(1) Access to resource/content resources

<Image Source="/a.png" />
<Image Source="/xxx/x.png" />

(2) Access to loose resource files (Loose file)

<Image Source="pack://siteOfOrigin:,,,/a.png" />
<Image Source="c:\test\a.png" />

XAML compilation requires that all resource validation be validated, so a valid URI path must be used when using loose resource files. "pack://" represents the Package URI, "Pack://siteoforigin:,,," means starting at the deployment location, and the corresponding "Pack://application:,,," The full path to the Resource resource above should be "pack ://application:,,,/a.png ", but usually we use ellipsis.

<Image Source="pack://application:,,,/a.png" />

Other URI notation also includes the following:

<Image Source="http://www.qidian.com/images/logo.gif" />
<Image Source="\\server1\share\logo.gif" />
<Image Source="file://c:/test/logo.gif" />

(3) Access to resource files in other assemblies

Providing an alternative dedicated resource DLL is also a common programming technique, especially for multiple languages or skin-changing mechanisms. WPF's syntax for accessing other assembly resource files is somewhat odd.

pack://application:,,,/AssemblyReference;Component/ResourceName

Resources for other assemblies must be embedded in a Resource manner.

You cannot omit the backslash before "/assemblyreference".

Component is a keyword and must be included in the URI.

<Image Source="pack://application:,,,/Learn.Library;component/s.gif" />
<Image Source="/Learn.Library;component/s.gif" />

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.