WPF下的资源问题

来源:互联网 发布:淘宝买家评论怎么写 编辑:程序博客网 时间:2024/05/29 18:28

1, Img/aa.jpg   文件

  若编译为Content, 则同时Copy to output Directory 设置为Copy always,每次编译时 Img/aa.jpg 自动复制到Bin 目录下,

  在cs 代码中这样访问:    ImageBrush ib = new ImageBrush(new BitmapImage(new Uri("Img/mail.jpg", UriKind.RelativeOrAbsolute)));

  如果图片在A程序集中,要在B程序集中访问,B中写法同上

 

2若编译为Resource文件  (Winform中为Embedded),

 如果是在同一个程序集中访问,则ImageBrush ib = new ImageBrush(new BitmapImage(new Uri("../../Img/mail.jpg", UriKind.RelativeOrAbsolute)));

           或者 ImageBrush ib = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Img/mail.jpg", UriKind.RelativeOrAbsolute)));

  如果A程序集调用B程序集,同时B想访问B自己的img,   则 

          ImageBrush ib = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/HMWPFCore/Img/mail.jpg", UriKind.RelativeOrAbsolute)));

    或者是 (@"/CommonAnimationLibrary;component/ThumbImg/downin.jpg", "Slide", "SlideDownFadeIn"));