Two good screencasts on passing parameters to a Silverlight 2.0 Control are available on Silverlight.Net. The first from Mike Taulty demonstrates InitParameters as a property in the ASPX Silverlight control. The second from Tim Heuer demonstrates using InitParameters as well as how to pass in Querystring parameters. Both are worth a look.
The approach to passing Querystring parameters to a Silverlight 2.0 Control that works for me is pretty simple. We check for the presence of Querystrings in the app.xaml Application_Startup using the Silverlight HTML Bridge and pass those values to the page’s constructor.
private void Application_Startup(object sender, StartupEventArgs e)
int fid = HtmlPage.Document.QueryString[“fid”] != null ?
int.Parse(HtmlPage.Document.QueryString[“fid”].ToString()) : -1;
int pid = HtmlPage.Document.QueryString[“pid”] != null ?
int.Parse(HtmlPage.Document.QueryString[“pid”].ToString()) : -1;
this.RootVisual = new InField.Grid(fid, pid);
GRID.XAML STARTUP PAGE ———————–
private int employeeID = 1;
private int postID = 1;
public Grid(int _employeeID, int _postID)
employeeID = _employeeID;
postID = _postID;
editing = false;
That’s the rough cut. The videos cover additional concepts. Tim Heuer’s video includes downloadable sample code in both VB and C#. Lots of useful information also in MSDN Library “Intergrating Silverlight with a Web Page.”