Thursday, August 05, 2010

Using RichTextBox in Silverlight 4

Introduction and Background
This is my first article on CodeProject.
Although Silverlight 4.0 was released in April 2010, numerous examples already abound for its new features. These include examples demonstrating the RichTextBox control as well. However, what I found was that most of these examples catered to runtime aspects, such as selecting user-typed text at runtime, and formatting it. The ubiquitous “text editor” and “Notepad” examples using Silverlight RichTextBox are what you'll mostly find if you did a Google search for the control. So what does one do if one wants to learn formatting a Silverlight RichTextBox at design through XAML? To answer this question, I demonstrate a simple example. Again, this example might seem rudimentary but it solves our objective – pure XAML code demonstrating how to format the RichTextBox. I have also thrown in a couple of other elements such as an Image and Hyperlink for good measure. Following this example, I also take up a few examples to showcase other features that the RichTextBox offers.
What You Will Need
Visual Studio 2010 (any version will do)
RichTextBox Control
The RichTextBox control in Silverlight 4.0 is a control that enables you to display or edit rich content. This content may include formatted paragraphs, hyperlinks, and inline images.
Creating the Example
Create a Silverlight 4.0 application using Visual Studio 2010. Name it as RichTextDemo. Drag and drop a RichTextBox from the ToolBox onto the MainPage.
Read more: Codeproject