Skip to main content

SnapshotNode Class

Definition​

Assembly:Avalonia.Controls.Documents
Package:Avalonia.Controls.Documents

Base class for all snapshot nodes. Contains no UI references. All data is owned by the snapshot and safe to access from any thread.

public class SnapshotNode

Remarks​

SnapshotNode is designed for serialization scenarios (RTF/HTML export, autosave). It captures a point-in-time view of the document structure.

Memory per node varies by subtype:

Methods​

NameDescription
ChildrenOfKindEnumerates child nodes matching a specific kind.
EnumerateDescendantsEnumerates this node and all descendants in pre-order (depth-first).
GetFormatMetadataNo summary available.
SetFormatMetadataNo summary available.

ChildrenOfKind Method​

Enumerates child nodes matching a specific kind.

public System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode> ChildrenOfKind(Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind kind)

Parameters​

kind Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind

Returns​

System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode>

EnumerateDescendants Method​

Enumerates this node and all descendants in pre-order (depth-first).

public System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode> EnumerateDescendants()

Returns​

System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode>

GetFormatMetadata Method​

public T GetFormatMetadata<T>()

Type Parameters​

T

Returns​

T

SetFormatMetadata Method​

public void SetFormatMetadata<T>(T metadata)

Parameters​

metadata T

Type Parameters​

T

Properties​

NameDescription
ChildrenChild nodes. Empty array for leaf nodes.
CustomDataExtension-specific custom data for custom node kinds. Used by the builder path (Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshotBuilder) to propagate custom data from serializer importers to snapshot nodes. Must be immutable or thread-safe for background serialization.
EndOffsetGets the absolute end offset (exclusive).
FormatMetadataFormat-specific metadata for round-trip fidelity. Serializers (RtfWriter, DocxWriter, etc.) can attach format-specific state here to preserve information that doesn't map cleanly to the semantic snapshot model. Not thread-safe; single-threaded access only.
IsBlockGets whether this is a block-level node.
IsInlineGets whether this is an inline-level node.
IsLeafGets whether this is a leaf node (no children).
IsTextRunGets whether this node represents a text run with actual content.
KindThe kind of document element this node represents.
LengthLength of this node's content in characters.
StartOffsetAbsolute offset in the document text where this node starts.
TextElementFormattingBase-level formatting from Avalonia.Controls.Documents.RichTextElement. Carries font, foreground, background, and letter-spacing for every node type.

Children Property​

Child nodes. Empty array for leaf nodes.

public Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNodeChildren Children { get; set; }

CustomData Property​

Extension-specific custom data for custom node kinds. Used by the builder path (Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshotBuilder) to propagate custom data from serializer importers to snapshot nodes. Must be immutable or thread-safe for background serialization.

public object CustomData { get; set; }

EndOffset Property​

Gets the absolute end offset (exclusive).

public int EndOffset { get; set; }

FormatMetadata Property​

Format-specific metadata for round-trip fidelity. Serializers (RtfWriter, DocxWriter, etc.) can attach format-specific state here to preserve information that doesn't map cleanly to the semantic snapshot model. Not thread-safe; single-threaded access only.

public object FormatMetadata { get; set; }

Remarks​

Example: RTF uses twips for measurements and has 15 border types. The snapshot uses DIPs and 5 semantic border styles. Format metadata preserves original values for perfect round-trip fidelity.

The raw slot is internal: Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode.GetFormatMetadata<T> and Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode.SetFormatMetadata<T>(<>) are the surface, and the type argument is what makes a reader's expectation legible at the call site.

IsBlock Property​

Gets whether this is a block-level node.

public bool IsBlock { get; set; }

IsInline Property​

Gets whether this is an inline-level node.

public bool IsInline { get; set; }

IsLeaf Property​

Gets whether this is a leaf node (no children).

public bool IsLeaf { get; set; }

IsTextRun Property​

Gets whether this node represents a text run with actual content.

public bool IsTextRun { get; set; }

Kind Property​

The kind of document element this node represents.

public Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind Kind { get; set; }

Length Property​

Length of this node's content in characters.

public int Length { get; set; }

StartOffset Property​

Absolute offset in the document text where this node starts.

public int StartOffset { get; set; }

TextElementFormatting Property​

Base-level formatting from Avalonia.Controls.Documents.RichTextElement. Carries font, foreground, background, and letter-spacing for every node type.

public Avalonia.Controls.Documents.TextModel.Formatting.TextElementFormatting TextElementFormatting { get; set; }