Skip to content

RichTextBox class

Defined in

Namespace: CrissCross.Avalonia.UI.Controls Assembly: CrissCross.Avalonia.UI.dll Full name: CrissCross.Avalonia.UI.Controls.RichTextBox Modifiers: public

Summary

        Represents a rich editing control that provides multi-line text editing capabilities with visual formatting.
        Supports bold, italic, underline, and strikethrough formatting via keyboard shortcuts and context menu.
        

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net471

Class hierarchy
classDiagram
class RichTextBox
class TemplatedControl
TemplatedControl <|-- RichTextBox

Inherits from: TemplatedControl

Remarks

Key features matching WPF RichTextBox:

  • Multi-line text editing with word wrap.
  • Visual text formatting (Bold, Italic, Underline, Strikethrough).
  • Keyboard shortcuts (Ctrl+B, Ctrl+I, Ctrl+U).
  • Context menu with formatting options.
  • Undo/Redo support.
  • Save/Load content to/from files or streams.

Constructors

NameSummary
.ctorInitializes a new instance of the [RichTextBox](# class.

Properties

NameSummary
TextGets or sets the text content.
AcceptsReturnGets or sets a value indicating whether Enter inserts a new line.
AcceptsTabGets or sets a value indicating whether Tab inserts a tab character.
IsReadOnlyGets or sets a value indicating whether the control is read-only.
IsTextSelectionEnabledGets or sets a value indicating whether text selection-only mode is enabled.
TextWrappingGets or sets the wrapping mode.
HorizontalScrollBarVisibilityGets or sets the horizontal scroll bar visibility.
VerticalScrollBarVisibilityGets or sets the vertical scroll bar visibility.
CaretBrushGets or sets the caret brush.
SelectionBrushGets or sets the selection brush.
WatermarkGets or sets the watermark text.
IsFormattingEnabledGets or sets a value indicating whether formatting is enabled.
IsDocumentEnabledGets or sets a value indicating whether content elements in the document are interactive.
IsDragDropEnabledGets or sets a value indicating whether drag and drop insertion is enabled.
EditModeGets or sets the edit/display mode.
IsRichClipboardEnabledGets or sets a value indicating whether HTML clipboard payloads are copied and pasted.
IsImagePasteEnabledGets or sets a value indicating whether image paste is enabled.
IsImageDropEnabledGets or sets a value indicating whether image drop is enabled.
MaxDroppedTextFileBytesGets or sets the maximum UTF-8 text file size accepted by runtime file drops.
ClipboardAdapterGets or sets the clipboard adapter used by copy, cut, and paste operations.
CanCopyGets a value indicating whether the current selection can be copied.
CanCutGets a value indicating whether the current selection can be cut.
CanPasteGets a value indicating whether the clipboard can be pasted into the current document.
CanUndoGets a value indicating whether undo history is available.
CanRedoGets a value indicating whether redo history is available.
CanApplyFormattingGets a value indicating whether formatting can be applied to the current selection.
CopyCommandGets the copy command.
CutCommandGets the cut command.
PasteCommandGets the paste command.
UndoCommandGets the undo command.
RedoCommandGets the redo command.
SelectAllCommandGets the select all command.
ToggleBoldCommandGets the bold formatting command.
ToggleItalicCommandGets the italic formatting command.
ToggleUnderlineCommandGets the underline formatting command.
ToggleStrikethroughCommandGets the strikethrough formatting command.
ClearFormattingCommandGets the clear formatting command.
SetFontFamilyCommandGets the font family formatting command.
SetFontSizeCommandGets the font size formatting command.
SetForegroundCommandGets the foreground color formatting command.
SetHighlightCommandGets the highlight color formatting command.
SelectionStartGets or sets the selection start index.
SelectionEndGets or sets the selection end index.
CaretIndexGets or sets the caret index.
DocumentGets the document model.
SelectionGets the text selection.
CaretPositionGets or sets the current caret position.
HasSelectionGets a value indicating whether text is selected.
SelectionLengthGets the current selection length.
SelectedTextGets the selected text.
SelectedHtmlGets the selected content as an HTML fragment preserving inline formatting where possible.

Fields

NameSummary
static TextPropertyProperty for [Text](#
static AcceptsReturnPropertyProperty for [AcceptsReturn](#
static AcceptsTabPropertyProperty for [AcceptsTab](#
static IsReadOnlyPropertyProperty for [IsReadOnly](#
static IsTextSelectionEnabledPropertyProperty for [IsTextSelectionEnabled](#
static TextWrappingPropertyProperty for [TextWrapping](#
static HorizontalScrollBarVisibilityPropertyProperty for [HorizontalScrollBarVisibility](#
static VerticalScrollBarVisibilityPropertyProperty for [VerticalScrollBarVisibility](#
static CaretBrushPropertyProperty for [CaretBrush](#
static SelectionBrushPropertyProperty for [SelectionBrush](#
static WatermarkPropertyProperty for [Watermark](#
static IsFormattingEnabledPropertyProperty for [IsFormattingEnabled](#
static IsDocumentEnabledPropertyProperty for [IsDocumentEnabled](#
static IsDragDropEnabledPropertyProperty for [IsDragDropEnabled](#
static EditModePropertyProperty for [EditMode](#
static IsRichClipboardEnabledPropertyProperty for [IsRichClipboardEnabled](#
static IsImagePasteEnabledPropertyProperty for [IsImagePasteEnabled](#
static IsImageDropEnabledPropertyProperty for [IsImageDropEnabled](#
static MaxDroppedTextFileBytesPropertyProperty for [MaxDroppedTextFileBytes](#
static SelectionStartPropertyProperty for [SelectionStart](#
static SelectionEndPropertyProperty for [SelectionEnd](#
static CaretIndexPropertyProperty for [CaretIndex](#
static TextChangedEventDefines the [TextChanged](# event.
static SelectionChangedEventDefines the [SelectionChanged](# event.
static FormattingAppliedEventDefines the [FormattingApplied](# event.

Methods

NameSummary
GetPositionFromPointReturns the text position nearest the provided point.
ShouldSerializeDocumentDetermines whether the document should be serialized.
GetPlainTextGets the rendered plain text for the current document.
GetHtmlGets the current HTML/markup representation for the document.
ToggleBoldApplies bold formatting to the selection.
ToggleItalicApplies italic formatting to the selection.
ToggleUnderlineApplies underline formatting to the selection.
ToggleStrikethroughApplies strikethrough formatting to the selection.
SetSelectionFontFamilyApplies a font family to the selected content.
SetSelectionFontSizeApplies a font size to the selected content.
SetSelectionForegroundApplies a foreground color to the selected content.
SetSelectionHighlightApplies a highlight color to the selected content.
SelectAllSelects all text.
SelectSelects a range by offset and length.
ClearClears all text.
ClearFormattingClears all formatting.
AppendTextAppends plain text to the end of the document.
AppendHtmlAppends HTML content to the end of the document.
SetHtmlReplaces the current content with HTML.
SetPlainTextReplaces the current content with plain text.
SetMarkdownReplaces the current content with markdown converted to HTML.
ReplaceSelectionReplaces the current selection with plain text.
ReplaceSelectionWithHtmlReplaces the current selection with HTML.
CopyCopies the selection to the clipboard.
CutCuts the selection to the clipboard.
PastePastes from the clipboard.
EnsureContextMenuEnsures that the RichTextBox context menu exists and returns it.
RefreshContextMenuStateRefreshes command enablement for the context menu items.
TryDropTextInserts a dropped text payload when drag/drop and edit state allow it.
TryDropImageInserts a dropped image source when drag/drop, image policy, and edit state allow it.
UndoUndoes the last action.
RedoRedoes the last undone action.
SaveSaves content to a stream.
GetMarkdownGets a Markdown-compatible text representation.
LoadLoads content from a stream.
OnApplyTemplateCalled when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.
OnPropertyChangedCalled when a avalonia property changes on the object.
OnKeyDownInvoked when an unhandled KeyDownEvent reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
OnPointerReleasedInvoked when an unhandled PointerReleasedEvent reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
OnGotFocusInvoked when an unhandled GotFocusEvent reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

Events

NameSummary
TextChangedOccurs when text changes.
SelectionChangedOccurs when selection changes.
FormattingAppliedOccurs when formatting is applied.
Inherited members