看,我有一个 html 文件,我正在尝试加载 iframe 和 Web 浏览器控件以外的其他控件,所以我使用了 RichTextBox,它是否仅支持 XAML?如果它也支持 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;
}
}
}
我哪里出错了...谢谢