Xceed Toolkit Plus for WPF v5.0 Documentation
Xceed.Wpf.Toolkit Assembly / Xceed.Wpf.Toolkit Namespace / RichTextBox Class
Members Example


In This Topic
    RichTextBox Class
    In This Topic
    Extends the System.Windows.Control.RichTextBox control that represents a rich editing control which operates on FlowDocument objects.
    Syntax
    'Declaration
     
    <LocalizabilityAttribute(LocalizationCategory.Inherit)>
    <ContentPropertyAttribute("Document")>
    <TemplatePartAttribute(Name="PART_ContentHost", Type=System.Windows.FrameworkElement)>
    <StyleTypedPropertyAttribute(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)>
    <XmlLangPropertyAttribute("Language")>
    <UsableDuringInitializationAttribute(True)>
    <RuntimeNamePropertyAttribute("Name")>
    <UidPropertyAttribute("Uid")>
    <TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
    <NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
    Public Class RichTextBox 
       Inherits System.Windows.Controls.RichTextBox
    'Usage
     
    Dim instance As RichTextBox
    [Localizability(LocalizationCategory.Inherit)]
    [ContentProperty("Document")]
    [TemplatePart(Name="PART_ContentHost", Type=System.Windows.FrameworkElement)]
    [StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]
    [XmlLangProperty("Language")]
    [UsableDuringInitialization(true)]
    [RuntimeNameProperty("Name")]
    [UidProperty("Uid")]
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public class RichTextBox : System.Windows.Controls.RichTextBox 
    Remarks

    The RichTextBox control has a Text dependency property that allows a user to data bind content to the RichTextBox.Document property.

    The RichTextBox control uses text formatters to allow a user to format the content of the RichTextBox control into any format of their choice. Three text formatters are included: PlainTextFormatter, RtfFormatter, and XamlFormatter. The RtfFormatter is the default text formatter. A user can create their own custom text formatter by creating a class that inherits from ITextFormatter and implementing its members accordlingly.

    When data binding to the Text property, you must use the Text Formatter that matches the format of the underlying data. If your data is in RTF, you must use RTFFormatter; if your data is in plain text, you must use the PlainTextFormatter; if your data is XML, you must use XmlFormatter.

    When using the RichTextBox with buttons to change the styles of your text such as bold, italics, etc., you will notice that the Text is not updated until the control loses focus. Therefore when you leave focus on the RichTextBox and start manipulating test with buttons, those changes will not be propogated properly. This is because by default, the source is not update until the RichTextBox control loses focus. To enable this behavior you must set the UpdateSourceTrigger to PropertyChanged on your Text property binding. This will force any change to the text to be updated through data binding to the underlying data source.

    Custom text formatters can be used by implementing the ITextFormatter interface (see ITextFormatter for details and examples).

    Example
    The following example shows how to use a text formatter other than the default RtfFormatter. The Notes property to which Text is bound contains "This is the RichTextBox\r\n".
    <xctk:RichTextBox x:Name="_richTextBox" Grid.Row="1" Margin="10" BorderBrush="Gray" Padding="10"
                                         Text="{Binding Notes}" 
                                         ScrollViewer.VerticalScrollBarVisibility="Auto">
                <xctk:RichTextBox.TextFormatter>
                    <xctk:PlainTextFormatter />
                </xctk:RichTextBox.TextFormatter>
    </xctk:RichTextBox>
    The following example shows how to use an RTF text formatter. The Notes property to which Text is bound contains "{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\ltrch This is the }{\b\ltrch RichTextBox}\li0\ri0\sa0\sb0\fi0\ql\par}}}".
    <xctk:RichTextBox x:Name="_richTextBox" Grid.Row="1" Margin="10" BorderBrush="Gray" Padding="10"
                                         Text="{Binding Notes}" 
                                         ScrollViewer.VerticalScrollBarVisibility="Auto">
                <xctk:RichTextBox.TextFormatter>
                    <xctk:RtfFormatter />
                </xctk:RichTextBox.TextFormatter>
    </xctk:RichTextBox>
    The following example shows how to use a text formatter other than the default RtfFormatter. The Notes property to which Text is bound contains XML.
    <xctk:RichTextBox x:Name="_richTextBox" Grid.Row="1" Margin="10" BorderBrush="Gray" Padding="10"
                                         Text="{Binding Notes}" 
                                         ScrollViewer.VerticalScrollBarVisibility="Auto">
                <xctk:RichTextBox.TextFormatter>
                    <xctk:XamlFormatter />
                </xctk:RichTextBox.TextFormatter>
    </xctk:RichTextBox>
    Inheritance Hierarchy

    System.Object
       System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
             System.Windows.Media.Visual
                System.Windows.UIElement
                   System.Windows.FrameworkElement
                      System.Windows.Controls.Control
                         System.Windows.Controls.Primitives.TextBoxBase
                            System.Windows.Controls.RichTextBox
                               Xceed.Wpf.Toolkit.RichTextBox

    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also