It is done by adding a
This is how you call the silverlight application. The line in bold shows how parameter is to be passed to the application.
<object data="data:application/x-silverlight,"
type="application/x-silverlight-2"
width="400" height="200">
<param name="source" value="InitParamsTest.xap"/>
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="favColor=Green"/>
<a href="http://go.microsoft.com/fwlink/?LinkID=124807">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181"
alt="Get Microsoft Silverlight"/>
a>
object>
type="application/x-silverlight-2"
width="400" height="200">
<param name="source" value="InitParamsTest.xap"/>
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="favColor=Green"/>
<a href="http://go.microsoft.com/fwlink/?LinkID=124807">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181"
alt="Get Microsoft Silverlight"/>
a>
object>
We now edit the App.xaml.cs to match our requirements like shown below.
public partial class App : Application
{
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
InitializeComponent();
}
private void Application_Startup(object sender,
StartupEventArgs e)
{
this.RootVisual = new Page(e.InitParams);
}
private void Application_Exit(object sender, EventArgs e)
{
}
}
{
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
InitializeComponent();
}
private void Application_Startup(object sender,
StartupEventArgs e)
{
this.RootVisual = new Page(e.InitParams);
}
private void Application_Exit(object sender, EventArgs e)
{
}
}
public partial class Page : UserControl
{
public Page(IDictionary<string, string> initParams)
{
InitializeComponent();
_TextField.Text = "My Favorite Color is: " + initParams["favColor"];
_TextField2.Text = "";
foreach (string key in initParams.Keys)
_TextField2.Text += key + ": " + initParams[key] + "\n";
}
}
The link to the Original Article......
{
public Page(IDictionary<string, string> initParams)
{
InitializeComponent();
_TextField.Text = "My Favorite Color is: " + initParams["favColor"];
_TextField2.Text = "";
foreach (string key in initParams.Keys)
_TextField2.Text += key + ": " + initParams[key] + "\n";
}
}
The link to the Original Article......
No comments:
Post a Comment