Load image dynamically on Silverlight
- by FelixMM
I have a Silverlight app that has to load an image dynamically, depending on the image name. The approach that im taking right now is passing the image name by query string to the page and passing that as a param to the Silverlight objet tag
This is the query string passed
Response.Redirect("Build.aspx?img=" + this.PictureUploader.PostedFile.FileName;
And I try to pass it to Silverlight like this:
<object id="SilverlightObject" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="Silverlight/iMapsSL.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<param name="image" value="<%# Request.QueryString["img"] %>" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
in the last param tag with name=image value= Requerst.QueryString
I catch the image inside the Silverlight app like this
private void Application_Startup(object sender, StartupEventArgs e)
{
string pictureName = "";
if (e.InitParams != null && e.InitParams.Count > 0)
{
pictureName = e.InitParams["image"];
this.RootVisual = new MainPage(pictureName);
}
else
{
this.RootVisual = new MainPage();
}
}
And when MainPage starts, I set the image source of the Image control like this
this.Image.Source = new BitmapImage(new Uri(pictureName, UriKind.RelativeOrAbsolute));
But Silverlight loads without an image, any help someone?