VS2010 Silverlight学习——启动xaml方式

参考资料:http://www.cnblogs.com/yaoge/category/244456.html
工具:Visual Studio 2010,Silverlight 3.0

目前知道的就2种方式。
1、直接在App.xaml.cs文件里修改当前启动的xaml
    private void Application_Startup(object sender, StartupEventArgs e)
        {
            //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>
    在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;
                }
            }
        }
posted @ 2011-05-27 17:48  程序新青年  阅读(424)  评论(0编辑  收藏  举报
============================================================================== 青春匆匆,很多人都有自己的座右铭,鞭策自己前进,当没看到座右铭的时候又忘了自己要干什么,就这样天天立志,志天天立,最终还是那个初出茅庐的小菜鸟。从现在开始,慢慢去改掉懒惰的习惯。慢慢去加强学习,直到慢慢成功。==============================================================================