如何在Silverlight中设置Image.Source(代码落后)

Dra*_*cir 30 silverlight

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

我该如何设置来源?

Gau*_*tam 54

你是怎么说它不接受字符串作为源?

你不能这样做吗?

或者你是说你的形象是在记忆中,你不知道如何参考它?

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

  • 我的项目需要附加"components":this.MyImage.Source = new BitmapImage(new Uri("/ MyNameSpace; components/images/someimage.png",UriKind.Relative)); (4认同)

Mal*_*ine 6

// create a new image
Image image = new Image();

// better to keep this in a global config singleton
string hostName = Application.Current.Host.Source.Host;                   
if (Application.Current.Host.Source.Port != 80)
    hostName += ":" + Application.Current.Host.Source.Port;

// set the image source
image.Source = new BitmapImage(new Uri("http://" + hostName + "/image111.jpg", UriKind.Absolute));  
Run Code Online (Sandbox Code Playgroud)