尝试了你的两种方法:
第一种的确不能显示图片,但是第二种应该是可以显示图片的。当然我们需要确保if条件成立才行。
请看下我的测试代码:
Paragraph para1 = new Paragraph();
BitmapImage bitmap = new BitmapImage(new Uri(@"\tushu\pic\1004.jpg"));
Image image = new Image();
image.Source = bitmap;
para1.Inlines.Add(image);
fdoc.Blocks.Add(para1);
Edit:添加XAML 代码:
<Window x:Class="RichTextBoxInsertImage.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel>
<RichTextBox Name="rtb">
<RichTextBox.Document>
<FlowDocument Name="fdoc"></FlowDocument>
</RichTextBox.Document>
</RichTextBox>
<Button Click="Button_Click">Test</Button>
</StackPanel>
</Grid>
</Window>
测试程序请替换掉图片的路径。
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.