locked
Windows Store app - Changing font color in RichTextblock and adding text RRS feed

  • Question

  • How do i add text to a RicktextBlock.

    String greet = "HEY";

    String greet2 = "How are you";

    like adding greet and greet2 to the textblock.

    after that, how do i change the color and font of greet2?

    this class is a bit different from textblock so i am having trouble.

    Monday, February 25, 2013 7:36 AM

Answers

  • this way:

    RichTextBlock tb = new RichTextBlock();
                var p = new Windows.UI.Xaml.Documents.Paragraph();
                p.Inlines.Add(new Windows.UI.Xaml.Documents.Run { Foreground = new SolidColorBrush(Colors.Green), Text = "Line one"});
                p.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());
                p.Inlines.Add(new Windows.UI.Xaml.Documents.Run { Foreground = new SolidColorBrush(Colors.Red), Text = "Line two"});
    
    
                tb.Blocks.Add(p);


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by kalel111 Monday, February 25, 2013 12:23 PM
    Monday, February 25, 2013 8:42 AM

All replies

  • this way:

    RichTextBlock tb = new RichTextBlock();
                var p = new Windows.UI.Xaml.Documents.Paragraph();
                p.Inlines.Add(new Windows.UI.Xaml.Documents.Run { Foreground = new SolidColorBrush(Colors.Green), Text = "Line one"});
                p.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());
                p.Inlines.Add(new Windows.UI.Xaml.Documents.Run { Foreground = new SolidColorBrush(Colors.Red), Text = "Line two"});
    
    
                tb.Blocks.Add(p);


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by kalel111 Monday, February 25, 2013 12:23 PM
    Monday, February 25, 2013 8:42 AM
  • I noticed that the paragraph does not have a background color property.  Would that have to be set in the block?
    Monday, February 25, 2013 1:06 PM