最近在做有关silverlight的项目,用到了一些控件,遇到了一些很特殊的情况,修改Image控件的source属性值就是其中之一。下面介绍一下如何修改,直接用后台代码的形式给出,需要注意的就是要用uri的形式,而不能直接赋值:
Image image = new Image();
Uri uri = new Uri(story.IconFileName, UriKind.Relative);
ImageSource imgSource = new System.Windows.Media.Imaging.BitmapImage(uri);
image.SetValue(Image.SourceProperty, imgSource);
this.LayoutRoot.Children.Add(image);
[/c-sharp]