The latest release – Q1 2011 brought some great enhancements to the Silverlight RadRichTextBox and its new WPF counterpart. The newly introduced functionality spans from capabilities for editing rich text – multilevel lists and extended table support, to additional formatting options – incorporating annotations in the document with hyperlinks that navigate to them, and inserting comments at different positions in the document. The customization and extensibility, which the RichTextBox takes pride in, have also made a step forward with its - as of now - localizable UI and the possibilities to overwrite the existing key-bindings used for triggering commands. In addition, the list of supported import/export formats has been expanded to include RTF, thus providing for one more option to persist your rich documents. Last but not least, the design-time support has been boosted by a wizard that appears when you drop the rich text box on the designer surface in Visual Studio and guides you through the initial configuration of the control.
Adding comments to spots in the document can be particularly useful when you want to note some extra information without breaking the logical sequence of the text in the document. It can be used when you are revising a document to jot down some changes that might be done at some point in the future. These comments can be easily hidden, deleted, or printed if needed. Exporting/importing to popular formats comes also out of the box.
One of the most requested enhancements is multilevel bulleted and numbered lists. Changing the level of any list item can be done at any time with the Increase-Indent and Decrease-Indent buttons on the Home tab of the ribbon bar or by the key-bindings Tab and Shift+Tab respectively. There are default predefined list-styles and others, available as a gallery in the ribbon bar, or you can register and utilize custom ones through the API. What is more, preserving the list styles in documents, created by other programs, like MS Word, is also supported.
The table support of RichTextBox includes inserting tables, adding rows and columns to existing ones or deleting them. Other possible operations are copy/paste of tables preserving the formatting, setting fixed or auto column width and dynamic resize of the columns using thumbs or the document ruler. Moreover, you can specify different cell-alignment, cell-padding, cell-spacing and apply various colors to the cells. Non-uniform border colors and patterns are also ready, willing and able. These customizations can be performed through the context menu and the ribbon bar or through some new dialogues, specially designed to make the work with the rich text box as an editor simple and smooth.
We have also introduced support for bookmarks and hyperlinks which can point to external pages, as well as to annotations in the document. This is very convenient as it provides the means for easier navigation in the document and enables features like table of contents. One can also associate different pieces of text in the document to a particular source in a bibliography at the end of the document. It is also quite practical to use bookmarks when you are working on a long document and need to return to specific locations for editing. Rather than having to scroll through your document and re-read half of it, you can quickly return to previously marked places to resume your work.
The use of bookmarks is quite easy with the new dialog for managing bookmarks:
and the extended dialog for inserting hyperlinks:
Once you have created such a rich document, you just have to save it. Why not use the new RTF format provider? Most word processing software implementations support RTF format importing and exporting and you can use RTF to assure the interoperability between the RichTextBox and other controls. RTF being a text-based format, there is also an RtfDataProvider which you can use to bind the content of a RichTextBox’s document to a string property of your view model or even directly to the database.
Using the rich text box has never been easier now that the Visual Studio Design Time Wizard is here. It prompts you to choose between the most common scenarios – a text-box look-alike, a rich text editor with outlook similar to those of Microsoft Word or a read-only viewer. Depending on the choice you make, you are further asked if you wish to use different features that the RichTextBox has, such as spell checking, SelectionMiniToolBar and ContextMenu, export/import to different formats, etc.
Upon completing these 3 or 4 steps and clicking “Finish”, it not only generates in XAML the code that sets these properties and adds the additional controls (RadRichTextBoxRibbonUI, DocumentRuler and DocumentStatusBar), but also adds the required references to the assemblies that this functionality is implemented in. The only thing that is left for you is to add reference to the format providers and run the application to test how it works.
By default the rich text box executes commands on key combinations, such as CTRL+C, CTRL+V, CTRL+U, etc. Now, these key bindings can be overridden and customized to the liking of the user. This can be used in different cases, one of which being the input of some culture-specific characters that are inserted through key combinations. You can also add keyboard shortcuts for functions that do not have such. For example, you can define a key-binding for opening the spell-checking dialog, so that you can see what is wrong with “entrepreneur” without having to search for the mouse.
Another improvement of the RichTextBox is that all pop-ups and messages can be fully localized. If you want your application to reach a global audience, cost-effective localization of your product is one of the best and most economical ways to reach more customers. Localization is supported through the built-in mechanism in Silverlight and WPF and allows you to localize any string resource used by the RichTextBox. Once translated you might use your resources in both Silverlight and WPF projects without changing anything. For more information, you can refer to this article.
Any feedback is as always, most welcome!
Iva Toteva is a software developer and works closely with clients to assist them in utilizing the RadControls they use for the purposes of their application. The controls in her domain include RadRichTextBox, RadSpreadsheet and RadPdfViewer.
Subscribe to be the first to get our expert-written articles and tutorials for developers!