2012-05-04 64 views
2

看到,我有一個html文件,我想加載除iframe和網頁瀏覽器控件以外的其他內容 因此我使用RichTextBox是否僅支持XAML?如果它也支持HTML.how我會執行。在Silverlight RichTextBox中加載HTML內容?

我試圖加載一個html文件,但它作爲文本加載。

下面是我的代碼。

<Grid x:Name="LayoutRoot" Background="White"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="400"/> 
     <ColumnDefinition Width="580"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <Canvas> 
    <TextBox Height="23" x:Name="txtFileName" Canvas.Left="15" Canvas.Top="40" Grid.Row="0" Grid.Column="0" Width="280" /> 
     <Button Content="Browse" Height="23" HorizontalAlignment="Left" x:Name="btnBrowse" Canvas.Left="300" Canvas.Top="40" Grid.Row="0" Grid.Column="0" Width="75" Click="BtnBrowse_Click" /> 

     <RichTextBox x:Name="rtxtboxHTML" Margin="3" Grid.Row="0" Grid.Column="1" Width="450" Height="400" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="450" Canvas.Top="40" IsReadOnly="True" TextWrapping="Wrap"/> 

    </Canvas> 
</Grid> 

private void BtnBrowse_Click(object sender, RoutedEventArgs e) 
    { 

     OpenFileDialog openFileDialog = new OpenFileDialog(); 
     openFileDialog.Filter = "Html files (*.html)|*.htm|All Files (*.*)|*.*"; 

     if (openFileDialog.ShowDialog()==true) 
     { 
      txtFileName.Text = openFileDialog.File.Name; 
      FileInfo _File = openFileDialog.File; 

      using (StreamReader strReader = new StreamReader(openFileDialog.File.OpenRead())) 
      { 
       string _strTemp = string.Empty; 
       //var rs = Application.GetResourceStream(new Uri(openFileDialog.File.Name, UriKind.Relative)); 
       //StreamReader sr = new StreamReader(rs.Stream); 
       while (!strReader.EndOfStream) 
       { 
        _strTemp = strReader.ReadToEnd(); 
       } 
       strReader.Close(); 
       rtxtboxHTML.Selection.Text = _strTemp; 
      } 
     } 
    } 

我哪裏錯了... 謝謝

+0

如果您需要一些詳盡的資料,您可能需要試用HTML Agility Pack:https://www.microsoft.com/getsilverlight/locale/en-us/html/Microsoft%20Silverlight%20Release%20History.htm#SL_5_1_10411 – jv42

回答

1

RichTextBox不會爲你解析HTML。

+0

謝謝..有什麼辦法來加載HTML? –