WPF Blog Writer by Lester

This past winter, I had coded a custom control which has a RichTextBox with toolbar for various formatting commands. I had hoped to publish it as a a standalone control sample which people could reuse, but it needed some styling to make the control look prettier. Lester has done a great job with that code and…


Printing Contents of WPF RichTextBox

I was recently playing with code to print contents of WPF RichTextBox control. The SDK has a code sample on this at http://msdn2.microsoft.com/en-us/library/aa970917.aspx             // Print RichTextBox content             private void PrintCommand()             {                 PrintDialog pd = new PrintDialog();                 if ((pd.ShowDialog() == true))                 {                     //use either one of the below                          pd.PrintVisual(richTB as…


Auto-detecting Hyperlinks in RichTextBox - Part II

In my previous post, we looked at code that auto-formats hyperlink strings while typing. The remaining part was to scan words when content is pasted in RichTextBox to auto-format any hyperlink strings. The approach to do this is quite straight forward as you can imagine. Listen to DataObject.Pasting event on RichTextBox, set a flag to remember the…


Replying to Messages

I received a few questions from my blog readers in email. I will try my best to answer them in this post. Question 1: Hi there! I saw that you were posting about the use of RichTextBox control and I thought you might be able to help me on my problem: how can I get the…


Navigate Words in RichTextBox

A commonly asked question on the WPF forum is – how can I navigate RichTextBox’s content word by word (see http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=778441&SiteID=1). In today’s post, we will see how this can be done using the TextPointer API. What we need is a helper function which takes a TextPointer position and returns us the word start and word…


Auto-detecting Hyperlinks in RichTextBox - Part I

In this post, we will see a custom RichTextBox implementation that auto-detects Hyperlinks while typing. In a later post, I will demonstrate how auto-detection can be done on paste command. Both these parts together enable complete auto-detect support for hyperlinks in a RichTextBox. For simplicity, in this demo, my code detects the string www.microsoft.com as a hyperlink….


Customize RichTextBox to allow only plain text input (with custom ContextMenu)

In this post, we will look at a custom RichTextBox implementation. In V1, TextBox selection highlight is not extensible and TextBox schema is restricted to plain text only. Often customers want a “rich” TextBox, where they can apply formatting properties (such as bold, underline) to Runs of text. I coded a sample that demonstrates how one…


FlowDocument Content Model

A while ago, I made up a UML diagram to illustrate WPF FlowDocument content model. This diagram is useful to understand the inheritance hierarchy of TextElement implementations and their TextElementCollection members. Check out the full diagram here. The one aspect of content schema this diagram doesn’t capture, is the fact that Hyperlink elements cannot be nested. Hope this helps!