Silverlight中嵌套html、swf、pdf

1.MainPage.xaml

 1 <UserControl x:Class="SilverlightClient.MainPage"
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"        
 5     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 6     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
 7   <Grid x:Name="LayoutRoot">
 8         <StackPanel>
 9             <!--导航栏-->
10             <StackPanel Orientation="Horizontal" Background="WhiteSmoke">
11                 <Button x:Name="myHTML" Content="HTML内容" FontSize="14"/>
12                 <Button x:Name="myFlash" Content="Flash" FontSize="14"/>
13                 <Button x:Name="myPDF" Content="PDF文档" FontSize="14"/>
14             </StackPanel>
15             <Grid x:Name="Container"/>
16         </StackPanel>
17     </Grid>
18 </UserControl>
View Code

2.MainPage.xaml.cs

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Net;
 5 using System.Windows;
 6 using System.Windows.Controls;
 7 using System.Windows.Documents;
 8 using System.Windows.Input;
 9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12 using Divelements.SilverlightTools;
13 
14 namespace SilverlightClient
15 {
16     public partial class MainPage : UserControl
17     {
18         public MainPage()
19         {
20             InitializeComponent();
21             //注册事件触发处理
22             this.Loaded += new RoutedEventHandler(MainPage_Loaded);
23             this.myHTML.Click += new RoutedEventHandler(myHTML_Click);
24             this.myFlash.Click += new RoutedEventHandler(myFlash_Click);
25             this.myPDF.Click += new RoutedEventHandler(myPDF_Click);
26         }
27 
28         void MainPage_Loaded(object sender, RoutedEventArgs e)
29         {
30             GetRichContent("http://cn.bing.com", UriKind.Absolute);
31         }
32 
33         void myPDF_Click(object sender, RoutedEventArgs e)
34         {
35             GetRichContent("/test.pdf",UriKind.Relative);
36         }
37 
38         void myFlash_Click(object sender, RoutedEventArgs e)
39         {
40             GetRichContent("/clock.swf", UriKind.Relative);
41         }
42 
43         void myHTML_Click(object sender, RoutedEventArgs e)
44         {
45             GetRichContent("http://cn.bing.com", UriKind.Absolute);
46         }
47 
48         //获取Rich Content
49         void GetRichContent(string uri,UriKind uk)
50         {
51             Container.Children.Clear();
52             ControlHtmlHost chtml = new ControlHtmlHost();
53             HtmlHost hh = chtml.FindName("htmlHost") as HtmlHost;
54             hh.SourceUri = new Uri(uri, uk);
55             Container.Children.Add(chtml);
56         }
57     }
58 }
View Code

3.添加Divelements.SilverlightTools.dll文件

4.在服务端添加相应的访问文件

Silverlight中嵌套html、swf、pdf,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。