我需要在一段文字中加上一个图片。但是,在添加文本之后,我需要插入图像。我知道我能做到
Paragraph firstParagraph = new Paragraph();
firstParagraph.Inlines.Add(new System.Windows.Controls.Image());
firstParagraph.Inlines.Add(new Run("Some text"));效果很好。
然而,如果我似乎不能做到这一点:
Paragraph secondParagraph = new Paragraph();
secondParagraph.Inlines.Add(new Run("Some text"));
secondParagraph.Inlines.InsertBefore(secondParagraph.Inlines.FirstInline, new Image());(显然,以上是一个人为的例子,在我的现实世界的例子中,我得到了一长串段落,我无法控制。我需要在一些照片的前面插入一张图片。)
发布于 2013-05-15 12:59:48
首先,你需要知道插入哪里。你需要一个TextPointer。
如果您使用的是RichTextBox,并且希望在光标位置插入,请尝试:
RichTextBox.Name = "rtb";您的System.Windows.Controls.Image名称: img
TextPointer insertHere = rtb.CaretPosition.GetInsertionPosition(LogicalDirection.Forward);
new InlineUIContainer(img, insertHere);https://stackoverflow.com/questions/10233152
复制相似问题