开发者

WPF: How do I set the content of a Paragraph in Code?

I've got a FlowDocument and assigned a name to one paragraph.

I want to edit the content of a paragrap开发者_运维问答h (which is just one ordinary string btw.).

How to do this?


var paragraph = new Paragraph();
paragraph.Inlines.Add(new Run(yourString));
flowDocument.Blocks.Add(paragraph);


To change the text of an existing paragraph can be done this way. (Individual formattings of the paragraph get lost!)

// myParagraph is the paragraph with the old text

while (myParagraph.Inlines.Count > 0)
    myParagraph.Inlines.Remove(myParagraph.Inlines.ElementAt(0));

myParagraph.Inlines.Add(new Run("new text"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜