VS2010 Silverlight学习——启动xaml方式

目前知道的就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;
                }
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值