开发者

Using <p> in Silverlight

How can I display my text as it is, means if it has paragraph it should display in that way only?. I am using <TextBlock>.

For example.

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.

kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk开发者_开发技巧kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.

lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll.

Thanx


The TextBlock in Silverlight supports very simple formatting only. A RichTextBox (set IsReadOnly, with a few other formatting settings) might be a better choice in some situations.

You might try something like this when using a TextBlock:

<TextBlock>
    <Run Text="Paragraph 1"/><LineBreak/><Run/>
    <LineBreak/>
    <Run Text="Paragraph 2"/><LineBreak/>
    <Run Text="No visible break."/>
    <LineBreak/>
    <Run Text="Paragraph 3"/><LineBreak/><Run/>
    <LineBreak/>
    <Run Text="End"/>
</TextBlock>

That would produce a block of text like this:

Paragraph 1

Paragraph 2
No visible break.
Paragraph 3

End

If you had existing markup, you could use string replacement or regular expressions to do some of the adjustments for you. For example, this might work:

A <p> could be a <Run>.

A </p> could be a </Run><LineBreak/><LineBreak/>.


The best way to do this is to add the line breaks yourself or divide it up in multiple elements using code that loops through an array of all text that was split anywhere there was a line break.

This is how I fixed that:

public String Body { get; set; }

// Assign a string to Body

Body = Body.Replace("\n", "\n\n");
Body = Body.Replace("\r", "\r\r");

Then I assigned Body to the TextBlock:

txt_article.Text = Body;

Hope it helps :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜