目前知道的就2种方式。
1、直接在App.xaml.cs文件里修改当前启动的xaml
private
void Application_Startup(
object sender, StartupEventArgs e)
{
//SilverlightControl1是新建的xaml文件名称
this.RootVisual = new SilverlightControl1(); //new MainPage();
}
{
//SilverlightControl1是新建的xaml文件名称
this.RootVisual = new SilverlightControl1(); //new MainPage();
}
2、在.html页面或.aspx页面里添加启动参数,然后在App.xaml.cs获取启动参数,根据不同的参数运行不同的xaml文件。
如下:
在.html页面或.aspx页面添加红色字体部分:
<
div id=
"silverlightControlHost">
< object data= "data:application/x-silverlight-2," type= "application/x-silverlight-2" width= "100%" height= "100%">
< param name= "source" value= "ClientBin/Video.xap" />
< param name= "onError" value= "onSilverlightError" />
< param name= "background" value= "white" />
< param name= "minRuntimeVersion" value= "3.0.40818.0" />
< param name= "autoUpgrade" value= "true" />
< param name= "initParams" value= "StartParm=Grid" />
< a href= "http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style= "text-decoration:none">
< img src= "http://go.microsoft.com/fwlink/?LinkId=161376" alt= "获取 Microsoft Silverlight" style= "border-style:none" />
< /a>
< /object>< iframe id= "_sl_historyFrame" style= "visibility:hidden;height:0px;width:0px;border:0px">< /iframe>< /div>
< object data= "data:application/x-silverlight-2," type= "application/x-silverlight-2" width= "100%" height= "100%">
< param name= "source" value= "ClientBin/Video.xap" />
< param name= "onError" value= "onSilverlightError" />
< param name= "background" value= "white" />
< param name= "minRuntimeVersion" value= "3.0.40818.0" />
< param name= "autoUpgrade" value= "true" />
< param name= "initParams" value= "StartParm=Grid" />
< a href= "http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style= "text-decoration:none">
< img src= "http://go.microsoft.com/fwlink/?LinkId=161376" alt= "获取 Microsoft Silverlight" style= "border-style:none" />
< /a>
< /object>< iframe id= "_sl_historyFrame" style= "visibility:hidden;height:0px;width:0px;border:0px">< /iframe>< /div>
在App.xaml.cs文件里获取参数:
private
void Application_Startup(
object sender, StartupEventArgs e)
{
string start = "StartParm"; //对应.html页面或.aspx页面的参数里,value对应表达式的左边StartParm
if (!e.InitParams.ContainsKey(start)) //如果找不到对应的参数,则返回一个默认启动项
this.RootVisual = new MainPage();
else
{
switch (e.InitParams[start]) //根据参数不同启动不同xaml
{
case "Ellipse":
this.RootVisual = new GridExam();
break;
case "Grid": //此例中传进的StartParm=Grid,因此将启动名称为SilverlightControl1的xaml文件
this.RootVisual = new SilverlightControl1();
break;
case "Rect":
this.RootVisual = new RectExam();
break;
case "Full":
this.RootVisual = new Fullscreen();
break;
default:
this.RootVisual = new MainPage();
break;
}
}
}
{
string start = "StartParm"; //对应.html页面或.aspx页面的参数里,value对应表达式的左边StartParm
if (!e.InitParams.ContainsKey(start)) //如果找不到对应的参数,则返回一个默认启动项
this.RootVisual = new MainPage();
else
{
switch (e.InitParams[start]) //根据参数不同启动不同xaml
{
case "Ellipse":
this.RootVisual = new GridExam();
break;
case "Grid": //此例中传进的StartParm=Grid,因此将启动名称为SilverlightControl1的xaml文件
this.RootVisual = new SilverlightControl1();
break;
case "Rect":
this.RootVisual = new RectExam();
break;
case "Full":
this.RootVisual = new Fullscreen();
break;
default:
this.RootVisual = new MainPage();
break;
}
}
}