Silverlight嵌入HTML和Flash和PDF文件
2011-09-15 09:41
411 查看
在Silverlight中嵌入HTML、Flash和PDF文件,请按以下进行
HtmlHost
网站:http://www.divelements.co.uk/silverlight/tools.aspx
下载:http://www.divelements.co.uk/silverlight/SilverlightTools.1.0.1.zip
控件下载:http://files.cnblogs.com/waren168/SilverlightTools.1.0.2.zip
接着,就对该组件进行介绍并且通过实际范例讲述该组件的应用。
1、基本特性
组件所在命名空间:
Divelements.SilverlightTools
组件常用属性:
SourceUri:显示在该组件中的内容的URI。
SourceHtml:用该组件显示的超文本内容。
Document:显示在该组件中的内容的HTML。
组件常用事件:
DocumentReady:当在该组件中的内容的HTML加载完毕后触发该事件。
2、实例讲解
注意:该组件需在windowless模式下才能正常运行。因此,首先要对服务端文件夹下的SilverlightClientTestPage.aspx文件或SilverlightClientTestPage.html文件做如下修改:(绿字粗体部分为新添加的内容)
接着,将需要嵌入的Flash文件及PDF文件放置在服务端文件夹的根目录下。
右击SilverlightClient文件夹下的References,引入Divelements.SilverlightTools命名空间。按Ctrl+Shift+B编译。
然后,在SilverlightClient文件夹下新建一个Silverlight UserControl,将其命名为ControlHtmlHost.xaml。该文件内容如下:
以下是MainPage文件的内容:
MainPage.xaml.cs文件代码:
以下官方说明
This is an ongoing effort to providevarious simple controls and components of a production quality for free, forgeneral use. Anybody can use these tools, whether in free or commercialsoftware. At the moment we only have one control in the toolset,
but we hope toexpand it shortly. If you have any ideas (simple tools only please) feel freeto contact us about them.
Note that there is no installer for thesetools. Just extract the archive into a directory of your choice, read thelicense and use the choose items command in the Visual Studio toolbox to addthe controls to your toolbox, if desired.
Download Silverlight Tools 1.0.2
HtmlHost
Many people have a need to displayrichly-formatted content in Silverlight, and at present the options for doingso are very limited. There is no document model or rich text facilities, andcertainly no support for embedding HTML. This
control allows you to embed HTML anywhere in a Silverlightapplication by simply specifying raw HTML to display or,if you prefer, the URL to a web page.
The control works by asking the hostbrowser to create a DIV tag in which to display the HTML, and positioning itcleverly to match up with the Silverlight layout system. You should find thatthis "just works" as the HtmlHost control is dynamically
moved orshown (on a tab page, for example) or even if the Silverlight plugin itself ismoved. You must be using the Silverlightplugin in windowless mode to use this control.
This is how you use the control to hostlive or external web content.
And this is how you create HTML on thefly.
HtmlHost
网站:http://www.divelements.co.uk/silverlight/tools.aspx
下载:http://www.divelements.co.uk/silverlight/SilverlightTools.1.0.1.zip
控件下载:http://files.cnblogs.com/waren168/SilverlightTools.1.0.2.zip
接着,就对该组件进行介绍并且通过实际范例讲述该组件的应用。
1、基本特性
组件所在命名空间:
Divelements.SilverlightTools
组件常用属性:
SourceUri:显示在该组件中的内容的URI。
SourceHtml:用该组件显示的超文本内容。
Document:显示在该组件中的内容的HTML。
组件常用事件:
DocumentReady:当在该组件中的内容的HTML加载完毕后触发该事件。
2、实例讲解
注意:该组件需在windowless模式下才能正常运行。因此,首先要对服务端文件夹下的SilverlightClientTestPage.aspx文件或SilverlightClientTestPage.html文件做如下修改:(绿字粗体部分为新添加的内容)
<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/SilverlightClient.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="3.0.40624.0" /> <param name="autoUpgrade" value="true" /> <param name="windowless" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/> </a> </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div> </form>
接着,将需要嵌入的Flash文件及PDF文件放置在服务端文件夹的根目录下。
右击SilverlightClient文件夹下的References,引入Divelements.SilverlightTools命名空间。按Ctrl+Shift+B编译。
然后,在SilverlightClient文件夹下新建一个Silverlight UserControl,将其命名为ControlHtmlHost.xaml。该文件内容如下:
<UserControl x:Class="SilverlightClient.ControlHtmlHost" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:divtools="clr-namespace:Divelements.SilverlightTools;assembly=Divelements.SilverlightTools" Width="900" Height="530"> <Grid x:Name="LayoutRoot" Background="White"> <divtools:HtmlHost Name="htmlHost"/> </Grid> </UserControl>
以下是MainPage文件的内容:
<UserControl x:Class="SilverlightClient.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <Grid x:Name="LayoutRoot"> <StackPanel> <!--导航栏--> <StackPanel Orientation="Horizontal" Background="WhiteSmoke"> <Button x:Name="myHTML" Content="HTML内容" FontSize="14"/> <Button x:Name="myFlash" Content="Flash" FontSize="14"/> <Button x:Name="myPDF" Content="PDF文档" FontSize="14"/> </StackPanel> <Grid x:Name="Container"/> </StackPanel> </Grid> </UserControl>
MainPage.xaml.cs文件代码:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Divelements.SilverlightTools; namespace SilverlightClient { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); //注册事件触发处理 this.Loaded += new RoutedEventHandler(MainPage_Loaded); this.myHTML.Click += new RoutedEventHandler(myHTML_Click); this.myFlash.Click += new RoutedEventHandler(myFlash_Click); this.myPDF.Click += new RoutedEventHandler(myPDF_Click); } void MainPage_Loaded(object sender, RoutedEventArgs e) { GetRichContent("http://cn.bing.com", UriKind.Absolute); } void myPDF_Click(object sender, RoutedEventArgs e) { GetRichContent("/test.pdf",UriKind.Relative); } void myFlash_Click(object sender, RoutedEventArgs e) { GetRichContent("/clock.swf", UriKind.Relative); } void myHTML_Click(object sender, RoutedEventArgs e) { GetRichContent("http://cn.bing.com", UriKind.Absolute); } //获取Rich Content void GetRichContent(string uri,UriKind uk) { Container.Children.Clear(); ControlHtmlHost chtml = new ControlHtmlHost(); HtmlHost hh = chtml.FindName("htmlHost") as HtmlHost; hh.SourceUri = new Uri(uri, uk); Container.Children.Add(chtml); } } }
以下官方说明
This is an ongoing effort to providevarious simple controls and components of a production quality for free, forgeneral use. Anybody can use these tools, whether in free or commercialsoftware. At the moment we only have one control in the toolset,
but we hope toexpand it shortly. If you have any ideas (simple tools only please) feel freeto contact us about them.
Note that there is no installer for thesetools. Just extract the archive into a directory of your choice, read thelicense and use the choose items command in the Visual Studio toolbox to addthe controls to your toolbox, if desired.
Download Silverlight Tools 1.0.2
HtmlHost
Many people have a need to displayrichly-formatted content in Silverlight, and at present the options for doingso are very limited. There is no document model or rich text facilities, andcertainly no support for embedding HTML. This
control allows you to embed HTML anywhere in a Silverlightapplication by simply specifying raw HTML to display or,if you prefer, the URL to a web page.
The control works by asking the hostbrowser to create a DIV tag in which to display the HTML, and positioning itcleverly to match up with the Silverlight layout system. You should find thatthis "just works" as the HtmlHost control is dynamically
moved orshown (on a tab page, for example) or even if the Silverlight plugin itself ismoved. You must be using the Silverlightplugin in windowless mode to use this control.
This is how you use the control to hostlive or external web content.
<Grid x:Name="LayoutRoot" Background="White"> <Border Margin="30"> <!-- Embed HTML within the page --> <divtools:HtmlHost Name="htmlHost" SourceUri="http://www.google.com" /> </Border> </Grid>
And this is how you create HTML on thefly.
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(); }原文地址:http://www.cnblogs.com/waren168/archive/2011/05/30/2062981.html
相关文章推荐
- [转]在Silverlight中嵌入HTML、Flash和PDF文件
- [原创]在Silverlight中嵌入HTML、Flash和PDF文件
- Silverlight嵌入HTML和Flash和PDF文件(转)
- 使用activePDF Toolkit嵌入Flash文件
- html文件中flash视频格式(flv、swf)文件的嵌入方法
- flash嵌入html 在html网页代码中嵌入Flash文件的解决方案(上)
- html文件中flash视频格式(flv、swf)文件的嵌入方法
- activePDF Toolkit中如何嵌入Flash文件
- silverlight中嵌入html、swf、pdf
- flash嵌入html 在html网页代码中嵌入Flash文件的解决方案(下)
- 如何在html中嵌入多媒体对象(pdf,word,flash等,)很有用的,记下
- html文件中flash视频格式(flv、swf)文件的嵌入方法
- 用ireport和jasperreports制作带嵌入字体的pdf文件
- 史上最强php生成pdf文件,html转pdf文件方法
- Helloj2ee学Silverlight之四——如何通过JavaScript在HTML网页里嵌入SL程序
- Html生成PDF文件,并Zip打包下载
- html模板导出pdf文件
- .Net 把网页Html转PDF文件
- Silverlight中嵌套html、swf、pdf
- 在HTML页面中嵌入flex(flash),并向flex传参(一)