Silverlight 4 Beta includes a new RichTextArea control. RichTextArea enables you to display or edit rich content and has features like:
Creating a RichTextArea is simple, it is similar to creating any other control in Silverlight. You can set content in a RichTextArea using the Paragraph element (the content property itself is Blocks, which in turn is a collection of Paragraph elements).
Here’s some sample code that shows you how to create a RichTextArea with a paragraph and some bold text.
<RichTextArea VerticalScrollBarVisibility="Auto">
<Paragraph> A RichTextArea with <Bold>initial content</Bold> in it. </Paragraph>
</RichTextArea>
Here’s the C# code, which does the same thing as the above xaml.
private void ContentRTA()
{
//Create a new RichTextArea with its VerticalScrollBarVisibility property set to Auto. RichTextArea MyRTA = new RichTextArea(); MyRTA.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // Create a Run of plain text and some bold text. Run myRun1 = new Run(); myRun1.Text = "A RichTextArea with "; Bold myBold = new Bold(); myBold.Inlines.Add("initial content "); Run myRun2 = new Run(); myRun2.Text = "in it."; // Create a paragraph and add the Run and Bold to it. Paragraph myParagraph = new Paragraph(); myParagraph.Inlines.Add(myRun1); myParagraph.Inlines.Add(myBold); myParagraph.Inlines.Add(myRun2); // Add the paragraph to the RichTextArea. MyRTA.Blocks.Add(myParagraph); //Add the RichTextArea to the StackPanel. MySP.Children.Add(MyRTA);
//Create a new RichTextArea with its VerticalScrollBarVisibility property set to Auto.
RichTextArea MyRTA = new RichTextArea();
MyRTA.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
// Create a Run of plain text and some bold text.
Run myRun1 = new Run();
myRun1.Text = "A RichTextArea with ";
Bold myBold = new Bold();
myBold.Inlines.Add("initial content ");
Run myRun2 = new Run();
myRun2.Text = "in it.";
// Create a paragraph and add the Run and Bold to it.
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add(myRun1);
myParagraph.Inlines.Add(myBold);
myParagraph.Inlines.Add(myRun2);
// Add the paragraph to the RichTextArea.
MyRTA.Blocks.Add(myParagraph);
//Add the RichTextArea to the StackPanel.
MySP.Children.Add(MyRTA);
}
For more details , samples and VB code see RichTextArea reference and the RichTextArea Overview topics.
-Nitya.