如何将siilverlight与web集成

时间:2011-06-13 09:00:58

标签: silverlight silverlight-4.0

我能够通过为source参数提供正确的值来将silverlight xap文件集成到网站页面中。类似的东西:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="ClientBin/Demo3.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="4.0.50826.0" />
          <param name="uiculture" value="<%= System.Threading.Thread.CurrentThread.CurrentUICulture %>" />
          <param name="culture" value="<%= System.Threading.Thread.CurrentThread.CurrentCulture %>" />
          <param name="autoUpgrade" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object>

但是,问题是我的silverlight项目有多个页面,我想在一个站点的不同网页上单独显示。

查询:如何修改源param标签以加载特定的xaml页面?

如果这不可能比如何实现这个场景?

1 个答案:

答案 0 :(得分:2)

StartupEventArgs.InitParams Property

Silverlight处理程序:

private void Application_Startup(object sender, StartupEventArgs e)
{
    // look into e.InitParams property and let's say we can get the following variable:
    bool showPage1;

    // let's say we have two pages - Page1.xaml and Page2.xaml
    RootVisual = showPage1 ? (UIElement) new Page1() : new Page2();
}

html(参见 initParams ):

<object id="slPlugin1" width="300" height="50"
        data="data:application/x-silverlight-2," 
        type="application/x-silverlight-2" >
        <param name="source" value="ClientBin/SilverlightApplication.xap"/>
        <param name="initParams"
            value="id=slPlugin1,embeddingTechnique=objectElement"/>
        <!-- Installation HTML omitted. -->
    </object>