'Declaration Public Interface ITextFormatter
'Usage Dim instance As ITextFormatter
public interface ITextFormatter
'Declaration Public Interface ITextFormatter
'Usage Dim instance As ITextFormatter
public interface ITextFormatter
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.
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; } }
<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>
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