如何以编程方式设置图像源 [英] How to programmatically set the Image source
本文介绍了如何以编程方式设置图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当Image的Source属性设置如下时,图片来自 /Images/down.png
。
When the Image's Source property is set the following way, the picture is taken from /Images/down.png
.
我如何以编程方式执行相同的操作?
How would I do the same thing programmatically?
<Image x:Name="myImg" Source="/MyProject;component/Images/down.png" />
以下不起作用,因为Image.Source属性不是字符串类型。
The following would not work, since Image.Source property is not of a string type.
myImg.Source = "/MyProject;component/Images/down.png";
推荐答案
试试这个:
BitmapImage image = new BitmapImage(new Uri("/MyProject;component/Images/down.png", UriKind.Relative));
这篇关于如何以编程方式设置图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文