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.

The source for this section is located in the RichTextBoxView page in the ControlExamples directory of the WPUnleashed.Examples project in the downloadable sample code.

While the RichTextBox control for Windows Phone lacks the ability to be edited by the user, it does allow you to blend text and rich content in a way that is easier than, for example, nesting TextBlocks and other elements within a StackPanel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.34.198