0

我已经创建了这样的 RichTextBlock

RichTextBlock RTB = new RichTextBlock();

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

4

1 回答 1

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();

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

于 2013-05-23T15:07:54.943 回答