ほら、私は 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;
}
}
}
私が間違っていたところ...ありがとう