现在的位置: 首页 > 综合 > 正文

wp7 image 图片不显示 黑色

2012年07月10日 ⁄ 综合 ⁄ 共 871字 ⁄ 字号 评论关闭

情况一:build Action属性

本地的图片的默认属性build Action 为Resource 造成的!build Action 中Resource 生成的时候,会将图片生成到Dll中去,所以你的image控件就找不到了图片了。

右键你的图片文件属性,然后修改build Action 为了 Content

然后把Copy To OutPut 为了Always copy 就ok了

思考一:

另外设置Resource中的图片如何访问呢。当然是可以通过c#代码Application.GetResourceStream()方法来获取,具体可以参见以下代码

需要加入两个名称空间

using System.Windows.Media.Imaging;
using Microsoft.Phone;

//new Uri("/your application;component/图片地址",.....) 格式是固定的!不然会爆错的。

Stream stream
= App.GetResourceStream(new Uri("/Exercise3;component/images/content1.png", UriKind.Relative)).Stream;

// Decode the JPEG stream.
WriteableBitmap myBitmap = PictureDecoder.DecodeJpeg(stream);


// Add WriteableBitmap object to image control.
DllImage.Source = myBitmap;


情况二:

ContentMenu中,ContextMenu  父控件不可以 有图片。图片也会为黑色。太晚了明天在弄!

相关链接:

李鹏的博客中有解答更为详细哦  (推荐)

http://www.cnblogs.com/magicboy110/archive/2010/12/08/1899733.html

http://www.cnblogs.com/magicboy110/archive/2010/12/08/1899734.html

他的wp7开发解惑太给力了。

抱歉!评论已关闭.