In some cases maybe you want to initialize Silverlight application by passing some parameters to it.
There is several possible ways to do it. I will demonstrate one of the simplest.
Here what the application may look like. An ASP.NET page passing some value to page where Silverlight application is defined.
Startup page will contain one DropDownList with colors and one button to navigate to Silverlight page. User should choose one color press button and set background of the Grid in the Silverlight to that selected Color.
When user clicks Button following code will execute (on the Default.aspx).
protected void Button1_Click(object sender, EventArgs e)
{
Session["Color"] = DropDownList1.SelectedValue;
Server.Transfer(ResolveUrl("~/SessionSLTestPage.aspx"));
}
On the SessionSLTestPage.aspx we have code to initialize Silverlight:
protected void Page_Load(object sender, EventArgs e)
{
Xaml1.InitParameters = "mySession=" + Session["Color"];
}
In the Silverlight project change App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
string session1 = e.InitParams["mySession"];
this.RootVisual = new Page(session1);
}
and finally on the page add new constructor to be able to pass value.
public Page(string stringvalue)
{
InitializeComponent();
SolidColorBrush brush = new SolidColorBrush(FindColor(stringvalue));
LayoutRoot1.Background = brush;
}
Source code can be found here

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=2f1852fa-c9c1-406b-8f3f-c61e033f4a1d)
Very nice article. This is what I want exactly..
Thanks
By: lakshmi on February 18, 2010
at 10:40
hi.. can i know how to put that theme behind the source codes. i mean using that we can identify source code separately.. i want to use it in my blog
By: uwudamith on March 13, 2011
at 07:55
Thanks for sharing.
Do you know how to pass data from silverlight app to an aspx page?
please share.
Thanks
Deepak.
By: Deepak on April 15, 2011
at 11:31
check out this http://forums.silverlight.net/forums/p/14964/49510.aspx#49510
I had an example with something similiar.
By: dotnetninja on April 15, 2011
at 11:36