2012-04-19 54 views
1

我需要在一段文字旁邊加入圖片。不過,我需要在之後插入圖片已添加文字。 我知道我可以這樣做:將圖片插入內聯段落的列表

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()); 

(顯然,上面是一個人爲的例子,在我的現實世界的例子,我得到段一長串回來,在我無法控制,我需要在某些圖片的前面插入圖片。)

+0

爲什麼不能這樣做這個?有錯誤嗎?它不起作用嗎? – Dennis 2012-04-20 14:21:09

+0

是的,請詳細說明 – TheZenker 2012-04-24 15:31:09

回答

0

首先,您需要知道在哪裏插入。 您將需要一個TextPointer。

鑑於您正在使用一個RichTextBox,你想在光標所在位置嘗試插入:

RichTextBox.Name = "rtb"; 

您System.Windows.Controls.Image名稱:IMG

TextPointer insertHere = rtb.CaretPosition.GetInsertionPosition(LogicalDirection.Forward); 
new InlineUIContainer(img, insertHere);