2011-06-13 26 views
1

我能夠通過爲源參數提供正確的值來將silverlight xap文件集成到網站頁面中。喜歡的東西:如何將siilverlight與網頁集成

<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項目有,我想在不同的網頁,在網站分別顯示多個頁面。

查詢:如何修改源參數標籤以加載特定的xaml頁面?

如果這不可能比如何實現這個scenerio?

回答

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>  
+0

我是新來的Silverlight。你能指定我可以在哪寫Application_Startup事件嗎?另外,如果可能的話,你可以寫2行代碼來使用initParams來渲染一個特定的xaml文件。 – iMatoria 2011-06-13 09:57:07

+1

@iMatoria:http://msdn.microsoft.com/en-us/library/system.windows.application.startup(v=vs.95).aspx'Startup'處理程序 – Snowbear 2011-06-13 09:59:08

+0

它的工作。我在param標籤中使用了initParams。在App.xaml.c的Application_Startup事件中抓取它。並且能夠改變這個.RootLayout。但是,我正在使用只有1個xaml文件使用子窗口概念的商業應用程序。我怎樣才能將我從initParams獲得的值傳遞給mainPage.xaml。我嘗試在MainPage中創建一個屬性,並將其設置在Application_Startup中,並將相同的對象分配給RootVisual。但是,不工作。無論如何,我正在標記你的答案是正確的。 – iMatoria 2011-06-13 10:54:58