Xceed Toolkit Plus for WPF v5.0 Documentation
Xceed.Wpf.Toolkit Assembly / Xceed.Wpf.Toolkit Namespace / ITextFormatter Interface
Members Example


    ITextFormatter Interface
    Provides an interface for formatting text in the RichTextBox.
    Syntax
    'Declaration
     
    Public Interface ITextFormatter 
     
    'Usage
     
    Dim instance As ITextFormatter
    Remarks

    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.

    Example
    The following shows an example of implementing the ITextFormatter interface.
    public class MyFormatter : ITextFormatter
    {
            public string GetText(System.Windows.Documents.FlowDocument document)
            {
                return new TextRange(document.ContentStart, document.ContentEnd).Text;
            }
    
            public void SetText(System.Windows.Documents.FlowDocument document, string text)
            {
                new TextRange(document.ContentStart, document.ContentEnd).Text = text;
            }
     }
    The following shows how to use a custom ITextFormatter-derived class.
    <xctk:RichTextBox x:Name="_richTextBox" Grid.Row="1" Margin="10" BorderBrush="Gray" Padding="10"
                                         Text="{Binding Notes}" 
                                         ScrollViewer.VerticalScrollBarVisibility="Auto">
                <xctk:RichTextBox.TextFormatter>
                    <myCustomFormatter:MyFormatter />
                </xctk:RichTextBox.TextFormatter>
    </xctk: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