Formatting Text at Runtime

You can format text in a RichTextBox at the paragraph-level and inline-level at runtime. The following example shows how you can right-align the entire contents of the RichTextBox within a Button.Tap event handler:

void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e){    foreach (Block block in richTextBox1.Blocks)    {        block.TextAlignment = TextAlignment.Right;    }}

Figure 6.11 shows the contents of a RichTextBox after it has been right-aligned via a Button placed within the Paragraph.

Image

FIGURE 6.11 Tapping an inline Button causes the Paragraph to be right-aligned. ...

Get Windows® Phone 8 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.