在Silverlight裏面嵌入HTML/ASPX/URL/Document/SVG等

第一步:下載組件 Download Silverlight Tools 1.0.2 解壓縮,將dll文件放到合適的位置。 第二步:在工具欄右鍵 [Choose Items] 用[Browse]找到Divelements.SilverlightTools.dll,添加 第三步:將組件拖到silverlight編輯頁面中,這時自動添加了對命名空間的引用 xmlns:divtools= clr-namespace:Divelements.SilverlightT
  

  第一步:下載組件Download Silverlight Tools 1.0.2解壓縮,將dll文件放到合適的位置。

  第二步:在工具欄右鍵 [Choose Items] 用[Browse]找到Divelements.SilverlightTools.dll,添加

  第三步:將組件拖到silverlight編輯頁面中,這時自動添加了對命名空間的引用

xmlns:divtools="clr-namespace:Divelements.SilverlightTools;assembly=Divelements.SilverlightTools"

 

  第四步:在要嵌入的位置加入HtmlHost組件,例如:

<divtools:HtmlHost Name="htmlHost" SourceUri="http://localhost:2883/enbedded.aspx" />

 

  第五步:最後不要忘了在silverlight 的宿主頁,加上 <param name="Windowless" value ="true" />,否則會彈出窗口報錯“You must be using the Silverlight plugin in windowless mode to use this control.”,事例如下:

//以下來自silverlight自動生成的TestPage.aspx

<body>
    <form id="form1" runat="server"style="height:100%">
    <div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
          <param name="source" value="ClientBin/ECSDashboard.xap"/>
           ……
          <param name="autoUpgrade" value="true" />
          <param name="Windowless" value ="true" />
     </object>
    <div>
    </form>
</body>



----------------------------------------------

  直接加入Html內容,實例

private void Button_Click(object sender, RoutedEventArgs e)
{ 
    // Populate the control with html 
    StringBuilder html = new StringBuilder(); 
    html.AppendLine("<h1>Heading</h1>"); 
    html.AppendLine("<p>This is a paragraph <span style='color: red'>
using</span> CSS <strong>formatting</strong>.</p>"); 
    html.AppendLine("<ul><li>List Item 1</li><li>List Item 2</li></ul>");
    htmlHost.SourceHtml = html.ToString(); 
}


 

 

發佈了120 篇原創文章 · 獲贊 31 · 訪問量 48萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章