第一章 第二课 Using Resources

After this lesson, you will be able to:
■ Embed a binary resource in an application.
■ Retrieve a binary resource by using code.
■ Retrieve a binary resource by using pack URI syntax.
■ Access a resource in another assembly by using pack URI syntax.
■ Add a content file to an application.
■ Create a resource-only DLL.
■ Load and access a resource-only DLL.
■ Create a logical resource.
■ Create an application resource.
■ Access a resource in XAML.
■ Explain the difference between a static resource and a dynamic resource.
■ Create a resource dictionary.
■ Merge resource dictionaries.
■ Decide where to store a resource.
■ Access a resource object in code.
一、Binary Resources
Binary resources enable you to compile large binary files in your application assemblies and
retrieve them for use in your application. Binary resources are different from logical resources,
which can be defined and accessed in XAML files
1. Embedding Resources
Add the file to your project and set the file’s Build Action property to Resource. When the application is
compiled, the resource is compiled automatically as a resource and embedded in your application
Do not set the Build Action property to Embedded Resource, which embeds the resource
using a different resource management scheme that is less accessible from WPF
applications.
Using embeding Resources
<Image Source="Pics/Image1.jpg"></Image>
<Image Source="Pics\Image1.jpg"></Image>
<Image Source="pack://application:,,,/Pics/Image1.jpg" Margin="17,90,61,22" Name="Image1" Stretch="Fill"/>
Using embeded Resources in other assembly:
pack://application:,,,/<AssemblyName>;component/<Folder>/<FileName>
2. Content Files
Embedding filess would require the application to be recompiled, and the embedding files would require pack uri, so updated frequently files and media MediaPlayer and MediaElement controls do not support the pack URI syntax
 
How to add content files:
Set the Build Action property for this file to Content.
Set Copy To Output Directory property to Copy Always.
 
Using content files
<Image Source="pack://siteOfOrigin:,,,/OfficeFrontDoor.jpg"/>
 
The siteOfOrigin:,,, syntax means different things depending on the location from which
the application was originally installed. If the application is a full-trust desktop application
that was installed using Windows Installer, the siteOfOrigin:,,, syntax in a pack URI refers to
the root directory of the application.
If the application is a full-trust application that was installed using ClickOnce, the
siteOfOrigin:,,,
syntax refers to the Uniform Resource Locator (URL) or the Universal Naming
Convention (UNC) path from which the application was originally deployed.
For a partial-trust application deployed with ClickOnce or an XAML Browser Application
(XBAP), siteOfOrigin:,,, refers to the URL or UNC path that hosts the application.
Pack URIs that use the siteOfOrigin:,,, syntax always point to loose files (that is, files that
are copied to the output directory but are not compiled); they never point to embedded
resources. Thus, the files they reference should always exist in the directory specified by the
siteOfOrigin:,,, syntax in a loose, uncompiled state.
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/NewLand/archive/2011/06/01/2065317.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值