2012-09-05 50 views
0

我创建了一个RichTextBlock这样添加文本RichTextBlock控制

RichTextBlock RTB = new RichTextBlock(); 

但我不能找到一种方法,添加文字和网址的RichTextBlock。
我在想,如果我需要使用特定的或类似的东西

回答

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

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