首页 > 其他 > 详细

WPF 中资源路径的问题

时间:2014-06-10 19:33:12      阅读:341      评论:0      收藏:0      [点我收藏+]

WPF 中资源路径的问题

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

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

1
2
3
4
if (!UriParser.IsKnownScheme("pack"))  
        new System.Windows.Application();  

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

1
string s = System.IO.Packaging.PackUriHelper.UriSchemePack; 

  

WPF 中资源路径的问题,布布扣,bubuko.com

WPF 中资源路径的问题

原文:http://www.cnblogs.com/cw_volcano/p/3779645.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!