Class RichTextDocument
- Namespace
- RichEdit.Maui
- Assembly
- RichEdit.Maui.dll
Represents a stable, observable rich-text document that supports atomic range edits.
public sealed class RichTextDocument : INotifyPropertyChanged
- Inheritance
-
RichTextDocument
- Implements
- Inherited Members
Constructors
RichTextDocument()
Initializes an empty rich-text document.
public RichTextDocument()
Fields
ObjectReplacementCharacter
The object-replacement character used to reserve a logical text position for an inline object.
public const char ObjectReplacementCharacter = ''
Field Value
SoftLineBreakCharacter
The Unicode line-separator character used for a soft line break.
public const char SoftLineBreakCharacter = '\u2028'
Field Value
Properties
CanRedo
Gets whether an undone edit can be reapplied.
public bool CanRedo { get; }
Property Value
CanUndo
Gets whether a recorded edit can be undone.
public bool CanUndo { get; }
Property Value
CurrentSnapshot
Gets the immutable snapshot for the current document version.
public RichTextDocumentSnapshot CurrentSnapshot { get; }
Property Value
DefaultCharacterFormat
Gets the declared default character format.
public RichTextCharacterFormat DefaultCharacterFormat { get; }
Property Value
DefaultParagraphFormat
Gets the declared default paragraph format.
public RichTextParagraphFormat DefaultParagraphFormat { get; }
Property Value
IsModified
Gets whether the current content differs from the last marked saved state.
public bool IsModified { get; }
Property Value
IsUndoGroupOpen
Gets whether an explicit undo group is open.
public bool IsUndoGroupOpen { get; }
Property Value
Length
Gets the number of UTF-16 code units in the logical text.
public int Length { get; }
Property Value
RedoDescription
Gets the description of the next redo operation.
public string? RedoDescription { get; }
Property Value
Revision
Gets the current document identity and version as an opaque token.
public DocumentRevision Revision { get; }
Property Value
RtfText
Gets the canonical RTF representation of the complete document.
public string RtfText { get; }
Property Value
Remarks
The value is serialized lazily and cached by Version. View appearance and native theme defaults are never serialized.
Text
Gets the plain-text projection of the document.
public string Text { get; }
Property Value
Tracking
Gets the document's position and range tracking service.
public TextTracking Tracking { get; }
Property Value
UndoDescription
Gets the description of the next undo operation.
public string? UndoDescription { get; }
Property Value
Version
Gets the monotonically increasing document version.
public long Version { get; }
Property Value
Methods
BeginUndoGroup(string?)
Groups subsequent recorded edits into one undo unit.
public IDisposable BeginUndoGroup(string? description = null)
Parameters
descriptionstringAn optional description for the outermost undo unit.
Returns
- IDisposable
A scope to dispose after the grouped edits.
Remarks
Groups can nest and must be disposed in reverse order. Each edit still commits and notifies independently; this scope is not a rollback transaction. Undo and redo are unavailable until the outermost group closes. History-clearing edits and explicit history clearing are not allowed inside a group.
ClearUndoHistory()
Clears undo and redo without changing content or its saved state.
public void ClearUndoHistory()
CreateSavePoint()
Captures the current content state before saving its snapshot.
public RichTextSavePoint CreateSavePoint()
Returns
- RichTextSavePoint
A save point belonging to this document.
Edit(Action<RichTextDocumentEdit>, RichTextEditOptions)
Applies an atomic set of incremental document edits.
public RichTextChangeSet Edit(Action<RichTextDocumentEdit> edit, RichTextEditOptions options = default)
Parameters
editAction<RichTextDocumentEdit>A callback that describes the edits in transaction order.
optionsRichTextEditOptionsUndo and application metadata for the transaction.
Returns
- RichTextChangeSet
The committed change set, or an empty change set when no edit was made.
Exceptions
- ArgumentNullException
editis null.- InvalidOperationException
The callback attempts to start another mutation on the same document.
FromPlainText(string?)
Creates a plain-text document with normalized line endings and empty undo history.
public static RichTextDocument FromPlainText(string? text)
Parameters
textstringThe initial text, or null for an empty document.
Returns
- RichTextDocument
A new live document.
FromRtf(string)
Creates a document by parsing a complete RTF value.
public static RichTextDocument FromRtf(string rtfText)
Parameters
rtfTextstringThe RTF value to parse.
Returns
- RichTextDocument
A new rich-text document containing the parsed content.
Exceptions
- ArgumentNullException
rtfTextis null.- FormatException
rtfTextis not valid supported RTF.
GetCharacterFormat(TextSpan)
Summarizes declared character formatting in a document range.
public RichTextCharacterFormatSummary GetCharacterFormat(TextSpan range)
Parameters
rangeTextSpanThe range to inspect.
Returns
- RichTextCharacterFormatSummary
A character-format summary.
GetParagraphFormat(TextSpan)
Summarizes declared paragraph formatting in a document range.
public RichTextParagraphFormatSummary GetParagraphFormat(TextSpan range)
Parameters
rangeTextSpanThe range to inspect.
Returns
- RichTextParagraphFormatSummary
A paragraph-format summary.
GetText(TextSpan)
Returns the plain text in a bounded document range.
public string GetText(TextSpan range)
Parameters
rangeTextSpanThe range to read.
Returns
- string
The selected plain text.
MarkSaved()
Marks the current document state as saved.
public void MarkSaved()
MarkSaved(RichTextSavePoint)
Marks a captured state as saved without marking intervening edits as saved.
public void MarkSaved(RichTextSavePoint savePoint)
Parameters
savePointRichTextSavePointThe state whose corresponding snapshot was successfully saved.
Redo()
Reapplies the next content state and maps every attached view's selection through the change.
public void Redo()
Undo()
Restores preceding content and maps every attached view's selection through the change.
public void Undo()
Events
Changed
Occurs after an atomic document transaction is committed.
public event EventHandler<RichTextDocumentChangedEventArgs>? Changed
Event Type
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged