如何在Silverlight中设置Image.Source(代码隐藏)

如何在Silverlight中设置Image.Source(代码隐藏),silverlight,Silverlight,我通过Silverlight中的代码动态生成图像,显然图像源不接受字符串或Uri作为路径 如何设置源?您认为它不接受字符串作为源是什么意思 你不能这样做吗 或者你是说你的图像在内存中,你不知道如何引用它 this.MyImage.Source = new BitmapImage(new Uri("/MyNameSpace;images/someimage.png", UriKind.Relative)); 我需要替换以下内容以使解决方案正常工作: this.MyImage.Source = n

我通过Silverlight中的代码动态生成图像,显然图像源不接受字符串或Uri作为路径


如何设置源?

您认为它不接受字符串作为源是什么意思

你不能这样做吗

或者你是说你的图像在内存中,你不知道如何引用它

this.MyImage.Source = new BitmapImage(new Uri("/MyNameSpace;images/someimage.png", UriKind.Relative));

我需要替换以下内容以使解决方案正常工作:

this.MyImage.Source = new BitmapImage(new Uri("/MyNameSpace;components/images/someimage.png", UriKind.Relative));
MyNameSpace对我不起作用,但ExecutionGassemblyName起作用,因此:

Dim tmp As String() = Assembly.GetExecutingAssembly.FullName.Split(","c)
Dim path As String = "/" & tmp(0) & ";component/images/"
MyImage.Source = new BitmapImage(new Uri(path & "someImage.png"))

不接受字符串我的意思是,例如:MyImage.Source=“/MyNameSpace;images/someimage.png”像在asp.NET中一样。我的项目需要附加“组件”:this.MyImage.Source=新的位图图像(新的Uri(“/MyNameSpace;components/images/someimage.png”,UriKind.Relative));我也花了一点时间才弄明白。Guantam的答案看起来和我使用的一样。不过我不得不稍微修改一下,它在路径中不包含名称空间就可以工作,不需要使用HTTP协议。只要使用本地资源就可以了。
Dim tmp As String() = Assembly.GetExecutingAssembly.FullName.Split(","c)
Dim path As String = "/" & tmp(0) & ";component/images/"
MyImage.Source = new BitmapImage(new Uri(path & "someImage.png"))