RichTextBoxFormatBar

The RichTextBoxFormatBar is a contextual formtting toolbar that mimics the behavior of the Microsoft Office 2010 formatting bar. It can be attached to any Richtextbox control by using the RichTextBoxFormatBarManager. You can even create your own formatting bar and use it instead, but still have all the functionality the RichTextboxFormatBarManager provides.

Behavior

richtextformatbar_detailed_updated.jpg

The RichTextBoxFormatBar is a contextual text formatting toolbar that will apply text transformations to the selected text of a RichTextBox control. When the user is in the process of a selection, the RichTextBoxFormatBar will appear when the mouse is released after the selection. The RichTextBoxFormatBar will also appear during the last click of a "double-click" selection. While the RichTextFormatBar is shown, you may click on any number of text transformations to be applied to the selected text. When done, you may click anywhere else in the RichTextBox control or move your mouse outside of the RichTextBox control to hide the RichTextBoxFormatBar. You can also drag the RichTextBoxFormatBar to a different position if it shows in a position that is not desired by clicking and holding on the drag thumb and moving your mouse to the desired location.

Usage

richtextformatbar_in_richtextbox.jpg

You can add the RichTextBoxFormatBar to either the toolkit's RichTextBox or the default Windows RichTextBox. This is done by using the RichTextBoxFormatBarManager. You simply set the RichTextBoxFormatBarManager.FormatBar property to the desired IRichTextBoxFormatBar instance. The following snippet addsthe RichTextBoxFormatBar to the Entended WPF Toolit's RichTextBox.

<xctk:RichTextBox>
       <xctk:RichTextBoxFormatBarManager.FormatBar>
           <xctk:RichTextBoxFormatBar />
       </xctk:RichTextBoxFormatBarManager.FormatBar>
</xctk:RichTextBox>


The following snippet addsthe RichTextBoxFormatBar to the default Windows RichTextBox.

<RichTextBox>
       <xctk:RichTextBoxFormatBarManager.FormatBar>
           <xctk:RichTextBoxFormatBar />
       </xctk:RichTextBoxFormatBarManager.FormatBar>
</RichTextBox>


Create Your Own Format Bar

You create your own custom format bar by creating a custom/user control that implements the IRichTextBoxFormatBar interface and set the RichTextBoxFormatBarManager.FormatBar property to your new custom format bar instance.

<RichTextBox>
       <xctk:RichTextBoxFormatBarManager.FormatBar>
           <local:MyCustomFormatBar />
       </xctk:RichTextBoxFormatBarManager.FormatBar>
</RichTextBox>

Properties

Property Description
FontSizes Gets an array of font sizes.
Target Gets or sets the target RichTextBox.


Get 50+ awesome WPF controls in the Plus Edition.
---

Last edited May 9, 2013 at 8:52 PM by Kosmatos, version 10

Comments

BoucherS Jan 6 at 1:10 PM 
Hi, Please use the Discussions Tab to submit ideas. The bug refering to focus/deactivation in RichTextFormatBar will be fixed in v2.1.

John3983 Jan 3 at 6:59 PM 
This component is a great idea! Please can you try and fix the problems with focus/deactivation when using the keyboard or mouse. For example: try opening the size combo and selecting 34 with the mouse or try clicking in a combo box and using the up or down keys.

Many thanks.

Pavithra Apr 22, 2013 at 6:17 AM 
Hi,

We are using Richtextcontrol in our project, and
we are facing few issues with Richtext formatbar.

1) If we enter text with line space and then if we do bulleting/Numbering then line space are also bulleted.

2)for bulleting/Numbering Text if change the alignment only text will be alligne not the bulleting.

3)All font changes (Font, Color & Background color) goes off, while selecting text with different background color, font size, text color.


Please let us know how to fix these issues or any workaround.

Regards,
Pavithra

Farawin Jul 2, 2012 at 12:16 PM 
Very nice. I have a question though:
I'm trying to style the Extended WPF Toolkit RichTextBox like so:

<Style TargetType="{x:Type tk:RichTextBox}">
<Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="SpellCheck.IsEnabled" Value="True"/>
<Setter Property="tk:RichTextBoxFormatBarManager.FormatBar" Value="{x:Type tk:RichTextBoxFormatBar}"/>
</Style>
However at runtime it fails with a ArgumentNullException saying: "Value cannot be null. Parameter name: property".

What could be causing this behaviour?

I also tried this syntax:

<Style TargetType="{x:Type tk:RichTextBox}">
<Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="SpellCheck.IsEnabled" Value="True"/>
<Setter Property="tk:RichTextBoxFormatBarManager.FormatBar">
<Setter.Value>
<tk:RichTextBoxFormatBar />
</Setter.Value>
</Setter>
</Style>
Unfortunately it gave me the same exception.

marshalsea Oct 24, 2011 at 2:07 PM 
Thanks for the RTF Text box and this.
Found this for adding the toolbar programmatically, which could be useful to others: http://stackoverflow.com/questions/4610742/richtextbox-formatbar-in-code-behind

Microsoft.Windows.Controls.RichTextBox rtb_wording = new Microsoft.Windows.Controls.RichTextBox();
Microsoft.Windows.Controls.RichTextBoxFormatBar formatBar = new Microsoft.Windows.Controls.RichTextBoxFormatBar();
Microsoft.Windows.Controls.RichTextBoxFormatBarManager.SetFormatBar(rtb_wording, formatBar); //Static method on the BarManager

LisaTatum Nov 19, 2010 at 12:58 PM 
Nice nice nice, this shows quality and a real Office 2010 Format Bar!