c# - 如何以编程方式设置图像源

标签 c# image silverlight code-behind

当图像的 Source 属性按以下方式设置时,图片取自 /Images/down.png

我如何以编程方式做同样的事情?

<Image x:Name="myImg" Source="/MyProject;component/Images/down.png" />

以下内容无效,因为 Image.Source 属性不是字符串类型。

myImg.Source = "/MyProject;component/Images/down.png"; 

最佳答案

试试这个:

BitmapImage image = new BitmapImage(new Uri("/MyProject;component/Images/down.png", UriKind.Relative));

关于c# - 如何以编程方式设置图像源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6503424/

相关文章:

c# - 如何判断证书是否有私钥

c# - 按连接度划分图

html - tinyMCE - 在移动设备上移动图像并调整其大小

c# - Silverlight HTTP POST 几个变量,最简单的示例(最少代码)

c# - 如何通过互联网推送数据?

c# - 等待 HttpWebRequest.BeginGetResponse 在 Windows Phone 7 中完成

c# - Application.Restart 不好吗?

c# - LINQ:为什么要使用 ...Take(1).SingleOrDefault()?

javascript - 更改 dropzone.js 的默认功能

Java/Swing : ownership of the system clipboard