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¶
| Name | Summary |
|---|---|
| .ctor | Initializes a new instance of the [RichTextBox](# class. |
Properties¶
| Name | Summary |
|---|---|
| Text | Gets or sets the text content. |
| AcceptsReturn | Gets or sets a value indicating whether Enter inserts a new line. |
| AcceptsTab | Gets or sets a value indicating whether Tab inserts a tab character. |
| IsReadOnly | Gets or sets a value indicating whether the control is read-only. |
| IsTextSelectionEnabled | Gets or sets a value indicating whether text selection-only mode is enabled. |
| TextWrapping | Gets or sets the wrapping mode. |
| HorizontalScrollBarVisibility | Gets or sets the horizontal scroll bar visibility. |
| VerticalScrollBarVisibility | Gets or sets the vertical scroll bar visibility. |
| CaretBrush | Gets or sets the caret brush. |
| SelectionBrush | Gets or sets the selection brush. |
| Watermark | Gets or sets the watermark text. |
| IsFormattingEnabled | Gets or sets a value indicating whether formatting is enabled. |
| IsDocumentEnabled | Gets or sets a value indicating whether content elements in the document are interactive. |
| IsDragDropEnabled | Gets or sets a value indicating whether drag and drop insertion is enabled. |
| EditMode | Gets or sets the edit/display mode. |
| IsRichClipboardEnabled | Gets or sets a value indicating whether HTML clipboard payloads are copied and pasted. |
| IsImagePasteEnabled | Gets or sets a value indicating whether image paste is enabled. |
| IsImageDropEnabled | Gets or sets a value indicating whether image drop is enabled. |
| MaxDroppedTextFileBytes | Gets or sets the maximum UTF-8 text file size accepted by runtime file drops. |
| ClipboardAdapter | Gets or sets the clipboard adapter used by copy, cut, and paste operations. |
| CanCopy | Gets a value indicating whether the current selection can be copied. |
| CanCut | Gets a value indicating whether the current selection can be cut. |
| CanPaste | Gets a value indicating whether the clipboard can be pasted into the current document. |
| CanUndo | Gets a value indicating whether undo history is available. |
| CanRedo | Gets a value indicating whether redo history is available. |
| CanApplyFormatting | Gets a value indicating whether formatting can be applied to the current selection. |
| CopyCommand | Gets the copy command. |
| CutCommand | Gets the cut command. |
| PasteCommand | Gets the paste command. |
| UndoCommand | Gets the undo command. |
| RedoCommand | Gets the redo command. |
| SelectAllCommand | Gets the select all command. |
| ToggleBoldCommand | Gets the bold formatting command. |
| ToggleItalicCommand | Gets the italic formatting command. |
| ToggleUnderlineCommand | Gets the underline formatting command. |
| ToggleStrikethroughCommand | Gets the strikethrough formatting command. |
| ClearFormattingCommand | Gets the clear formatting command. |
| SetFontFamilyCommand | Gets the font family formatting command. |
| SetFontSizeCommand | Gets the font size formatting command. |
| SetForegroundCommand | Gets the foreground color formatting command. |
| SetHighlightCommand | Gets the highlight color formatting command. |
| SelectionStart | Gets or sets the selection start index. |
| SelectionEnd | Gets or sets the selection end index. |
| CaretIndex | Gets or sets the caret index. |
| Document | Gets the document model. |
| Selection | Gets the text selection. |
| CaretPosition | Gets or sets the current caret position. |
| HasSelection | Gets a value indicating whether text is selected. |
| SelectionLength | Gets the current selection length. |
| SelectedText | Gets the selected text. |
| SelectedHtml | Gets the selected content as an HTML fragment preserving inline formatting where possible. |
Fields¶
| Name | Summary |
|---|---|
| static TextProperty | Property for [Text](# |
| static AcceptsReturnProperty | Property for [AcceptsReturn](# |
| static AcceptsTabProperty | Property for [AcceptsTab](# |
| static IsReadOnlyProperty | Property for [IsReadOnly](# |
| static IsTextSelectionEnabledProperty | Property for [IsTextSelectionEnabled](# |
| static TextWrappingProperty | Property for [TextWrapping](# |
| static HorizontalScrollBarVisibilityProperty | Property for [HorizontalScrollBarVisibility](# |
| static VerticalScrollBarVisibilityProperty | Property for [VerticalScrollBarVisibility](# |
| static CaretBrushProperty | Property for [CaretBrush](# |
| static SelectionBrushProperty | Property for [SelectionBrush](# |
| static WatermarkProperty | Property for [Watermark](# |
| static IsFormattingEnabledProperty | Property for [IsFormattingEnabled](# |
| static IsDocumentEnabledProperty | Property for [IsDocumentEnabled](# |
| static IsDragDropEnabledProperty | Property for [IsDragDropEnabled](# |
| static EditModeProperty | Property for [EditMode](# |
| static IsRichClipboardEnabledProperty | Property for [IsRichClipboardEnabled](# |
| static IsImagePasteEnabledProperty | Property for [IsImagePasteEnabled](# |
| static IsImageDropEnabledProperty | Property for [IsImageDropEnabled](# |
| static MaxDroppedTextFileBytesProperty | Property for [MaxDroppedTextFileBytes](# |
| static SelectionStartProperty | Property for [SelectionStart](# |
| static SelectionEndProperty | Property for [SelectionEnd](# |
| static CaretIndexProperty | Property for [CaretIndex](# |
| static TextChangedEvent | Defines the [TextChanged](# event. |
| static SelectionChangedEvent | Defines the [SelectionChanged](# event. |
| static FormattingAppliedEvent | Defines the [FormattingApplied](# event. |
Methods¶
| Name | Summary |
|---|---|
| GetPositionFromPoint | Returns the text position nearest the provided point. |
| ShouldSerializeDocument | Determines whether the document should be serialized. |
| GetPlainText | Gets the rendered plain text for the current document. |
| GetHtml | Gets the current HTML/markup representation for the document. |
| ToggleBold | Applies bold formatting to the selection. |
| ToggleItalic | Applies italic formatting to the selection. |
| ToggleUnderline | Applies underline formatting to the selection. |
| ToggleStrikethrough | Applies strikethrough formatting to the selection. |
| SetSelectionFontFamily | Applies a font family to the selected content. |
| SetSelectionFontSize | Applies a font size to the selected content. |
| SetSelectionForeground | Applies a foreground color to the selected content. |
| SetSelectionHighlight | Applies a highlight color to the selected content. |
| SelectAll | Selects all text. |
| Select | Selects a range by offset and length. |
| Clear | Clears all text. |
| ClearFormatting | Clears all formatting. |
| AppendText | Appends plain text to the end of the document. |
| AppendHtml | Appends HTML content to the end of the document. |
| SetHtml | Replaces the current content with HTML. |
| SetPlainText | Replaces the current content with plain text. |
| SetMarkdown | Replaces the current content with markdown converted to HTML. |
| ReplaceSelection | Replaces the current selection with plain text. |
| ReplaceSelectionWithHtml | Replaces the current selection with HTML. |
| Copy | Copies the selection to the clipboard. |
| Cut | Cuts the selection to the clipboard. |
| Paste | Pastes from the clipboard. |
| EnsureContextMenu | Ensures that the RichTextBox context menu exists and returns it. |
| RefreshContextMenuState | Refreshes command enablement for the context menu items. |
| TryDropText | Inserts a dropped text payload when drag/drop and edit state allow it. |
| TryDropImage | Inserts a dropped image source when drag/drop, image policy, and edit state allow it. |
| Undo | Undoes the last action. |
| Redo | Redoes the last undone action. |
| Save | Saves content to a stream. |
| GetMarkdown | Gets a Markdown-compatible text representation. |
| Load | Loads content from a stream. |
| OnApplyTemplate | Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed. |
| OnPropertyChanged | Called when a avalonia property changes on the object. |
| OnKeyDown | Invoked 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. |
| OnPointerReleased | Invoked 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. |
| OnGotFocus | Invoked 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¶
| Name | Summary |
|---|---|
| TextChanged | Occurs when text changes. |
| SelectionChanged | Occurs when selection changes. |
| FormattingApplied | Occurs when formatting is applied. |