How do you set Image.Source in Silverlight(Code behind)

后端 未结 3 1445
礼貌的吻别
礼貌的吻别 2021-01-03 19:04

I am dynamically generating an image through code-behind in Silverlight and apparently the image source doesn\'t accept a string or Uri as a path.

How can I set the

3条回答
  •  没有蜡笔的小新
    2021-01-03 19:09

    // 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));  
    

提交回复
热议问题