将文本添加到RichTextBlock-control

时间:2012-09-05 14:45:14

标签: windows-phone-7

我已经创建了像这样的RichTextBlock

RichTextBlock RTB = new RichTextBlock();

但是我找不到向RichTextBlock添加文本和URL的方法。
我在想,如果我需要特定的使用或类似的东西

1 个答案:

答案 0 :(得分:2)

试试这个:

    // creat your RichTextBlock  
    RichTextBlock MyRTB = new RichTextBlock();

     // Create a Run of plain text and some bold text.
                Run myRun1 = new Run();
                myRun1.Text = "Some text here";
                myRun1.FontStyle = FontStyle.Oblique;
                myRun1.FontSize = 72;

                Run myRun2 = new Run();
                myRun2.Text = "Other text";
                myRun2.FontSize = 140;
                myRun2.Foreground = new SolidColorBrush(Colors.Red);

                // Create a paragraph and add the Run and Bold to it.
                Paragraph myParagraph = new Paragraph();
                myParagraph.Inlines.Add(myRun1);
                myParagraph.Inlines.Add(myRun2);

// add paragraphe to your RichTextBlock  blocks
                MyRTB.Blocks.Add(myParagraph);


// now, add RichTextBlock  to the grid (or any other controler in your page)    
                ParentGrind.Children.Add(MyRTB);
// update layoute
                ParentGrind.UpdateLayout();

这项工作很适合我动态添加和格式化文本