WPF 中资源路径的问题

 

WPF 中资源路径的问题

分类: .net WPF   2460人阅读  评论(1)  收藏  举报
 WPF 中资源路径的问题

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

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

 

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

[html]  view plain copy
  1. <ImageBrush ImageSource="pack://application:,,,/otherAssemblyName;component/subfolder/xxx.png"/>  

 

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

[html]  view plain copy
  1. <ImageBrush ImageSource="pack://siteoforigin:,,,./subfolder/xxx.png "/>  

 

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

[html]  view plain copy
  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 plain copy
  1. if (!UriParser.IsKnownScheme("pack"))   
  2. {  
  3.         new System.Windows.Application();   
  4. }  

 

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

[csharp]  view plain copy
  1. string s = System.IO.Packaging.PackUriHelper.UriSchemePack;  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值