码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 中资源路径的问题

时间:2018-03-09 14:10:24      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:current   eof   lock   pack   ring   pac   lis   round   log   

原文:WPF 中资源路径的问题

?WPF 中资源路径的问题

1. 引用当前工程的资源(注意xxxx.png的build action 应设置为Resource 或Embedded Resource)

[csharp]?view plaincopy
  1. <ImageBrush?ImageSource="/currentAssemblyName;component/subfoldername/xxxx.png"/>??

?

2. ?引用其它工程的资源? (注意xxxx.png的build action 应设置为Resource 或Embedded Resource)

  1. <ImageBrush?ImageSource="pack://application:,,,/otherAssemblyName;component/subfolder/xxx.png"/>??

?

3. 引用相对路径下的资源(注意最好将xxx.png 的copy to output directory属性设置成 always copy )

  1. <ImageBrush?ImageSource="pack://siteoforigin:,,,./subfolder/xxx.png?"/>??

?

4. 引用绝对路径下的资源?

  1. <ImageBrush?ImageSource="C:\test\xxx.png"/>??

?

5. 当在使用pack 前缀的路径时,如果出现如下错误:System.UriFormatException: Invalid URI: Invalid port specified, 而你使用的pack路径又确实没有错误。这是因为pack:// scheme 没有注册,解决方案有两个:

a.?????? 实例化一个System.Windows.Application, 在实例化过程中会调用PackUriHelper class

[csharp]?view plaincopy
  1. if?(!UriParser.IsKnownScheme("pack"))???
  2. {??
  3. ????????new?System.Windows.Application();???
  4. }??

?

b.????? 调用一次System.IO.Packaging.PackUriHelper.UriSchemePack????

[csharp]?view plaincopy
  1. string?s?=?System.IO.Packaging.PackUriHelper.UriSchemePack; ?

WPF 中资源路径的问题

标签:current   eof   lock   pack   ring   pac   lis   round   log   

原文地址:https://www.cnblogs.com/lonelyxmas/p/8533346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!