目前知道的就2種方式。
1、直接在App.xaml.cs文件裏修改當前啓動的xaml
{
//SilverlightControl1是新建的xaml文件名稱
this.RootVisual = new SilverlightControl1();//new MainPage();
}
2、在.html頁面或.aspx頁面裏添加啓動參數,然後在App.xaml.cs獲取啓動參數,根據不同的參數運行不同的xaml文件。
如下:
在.html頁面或.aspx頁面添加紅色字體部分:
<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文件裏獲取參數:
{
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;
}
}
}