【发布时间】:2009-12-27 07:00:01
【问题描述】:
我是刚开始使用 Silverlight 的初学者,有一个非常基本的问题。我想显示一个 .png 图像。我已经在 page.xaml 文件中完成了它,但我想在代码 (C#) 中完成它,以便我可以在我的程序运行时添加和删除图像。我看过一些代码,其中您将图像添加到画布的子项中,但是当我这样做时,不会显示任何图像。有人可以提供一些代码以及放在哪里吗?这是我一直在使用的。没有例外,但没有图像出现。
page.myCanvas.Children.Add(LoadImage("Image/MrBlue"));
public Image LoadImage(string resource)
{
Image img = new Image();
Uri uri = new Uri(resource, UriKind.Relative);
ImageSource imgSrc = new System.Windows.Media.Imaging.BitmapImage(uri);
img.SetValue(Image.SourceProperty, imgSrc);
return img;
}
图像设置为“资源”和“请勿复制”。
【问题讨论】:
标签: silverlight image