Have you checked out the new RichTextArea control?
Silverlight 4 Beta includes a new RichTextArea control. RichTextArea enables you to display or edit rich content and has features like:
- displaying hyperlinks
- displaying inline images or other UIElements like a Button
- Read-only mode
- Selection APIs
- Formatting text at run time
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);
}
For more details , samples and VB code see RichTextArea reference and the RichTextArea Overview topics.
-Nitya.
Comments
- Anonymous
December 06, 2009
Hi there, i think the RichTextArea is a great control. Glad to see some classes from WPF, even if there's just one Block-Subclass yet. :-) One simple question: Silverlight 4 Beta's TextBlock doesn't support the Inlines Hyperlink and InlineUIContainer. Will the TextBlock support those in the final Silverlight 4 release?