Skip to main content

ClipboardFormats Class

Definition​

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

Per-OS clipboard Avalonia.Input.DataFormat mapping used by Avalonia.Controls.Documents.Primitives.Components.ClipboardOperations to publish and probe rich document formats next to Avalonia.Input.DataFormat.Text.

public class ClipboardFormats

Inheritance: object -> ClipboardFormats

Remarks​

Format objects are cached as static singletons so that copy / paste hot paths do not allocate new Avalonia.Input.DataFormat<T> instances per call.

Only the canonical platform identifier is published on copy. On paste, alternative aliases are also probed where applicable (Linux ships both text/rtf and application/rtf; macOS Word may use com.microsoft.rtf-compatible).

Methods​

NameDescription
TryGetClipboardFormatReturns the rich Avalonia.Input.DataFormat<T> matching the supplied Avalonia.Controls.Documents.Serialization.IDocumentSerializer.FormatName, or when the format is unknown to the clipboard layer.

TryGetClipboardFormat Method​

Returns the rich Avalonia.Input.DataFormat<T> matching the supplied Avalonia.Controls.Documents.Serialization.IDocumentSerializer.FormatName, or when the format is unknown to the clipboard layer.

public Avalonia.Input.DataFormat<byte[]> TryGetClipboardFormat(string formatName)

Parameters​

formatName string

Serializer format name (case-insensitive).

Returns​

Avalonia.Input.DataFormat<byte[]>

Properties​

NameDescription
InProcessSnapshotIn-process-only format carrying a live Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot reference. Created via Avalonia.Input.DataFormat.CreateInProcessFormat<T>(string) so the value never crosses the platform clipboard boundary — every clipboard backend (Windows, X11, macOS, iOS, Browser) skips Avalonia.Input.DataFormatKind.InProcess entries when serializing to the OS clipboard. Consumed via Avalonia.Input.Platform.IClipboard.TryGetInProcessDataAsync, which returns the exact same Avalonia.Input.IAsyncDataTransfer instance the producer published on the same process.
RtfPrimary platform RTF format for the current OS:
RtfAliasesOptional fallback identifiers to probe on paste. Empty when the primary format is the only known identifier on the current OS.

InProcessSnapshot Property​

In-process-only format carrying a live Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot reference. Created via Avalonia.Input.DataFormat.CreateInProcessFormat<T>(string) so the value never crosses the platform clipboard boundary — every clipboard backend (Windows, X11, macOS, iOS, Browser) skips Avalonia.Input.DataFormatKind.InProcess entries when serializing to the OS clipboard. Consumed via Avalonia.Input.Platform.IClipboard.TryGetInProcessDataAsync, which returns the exact same Avalonia.Input.IAsyncDataTransfer instance the producer published on the same process.

public Avalonia.Input.DataFormat<Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshot> InProcessSnapshot { get; set; }

Remarks​

Used by Avalonia.Controls.Documents.Primitives.Components.ClipboardOperations to ship the document snapshot reference alongside RTF + plain text, providing a 100%-fidelity fast path for same-process copy/paste that bypasses serialization entirely. RTF/text remain on the clipboard as fallbacks for the cross-process and cross-app cases.

Rtf Property​

Primary platform RTF format for the current OS:

  • Windows: Rich Text Format (CF_RTF registered name)
  • macOS: public.rtf (UTI)
  • Linux: text/rtf (MIME)
public Avalonia.Input.DataFormat<byte[]> Rtf { get; set; }

Remarks​

Published as a Avalonia.Input.DataFormat<T> of byte array, not string. The Win32 clipboard backend writes Avalonia.Input.DataFormat<T> string payloads as UTF-16 wide chars, which Word and other RTF consumers cannot parse — they expect raw 7-bit ASCII bytes starting with {\rtf1. RTF is by spec ASCII (non-ASCII characters use \u / \'hh escapes), so UTF-8 bytes are interchangeable with ASCII bytes here.

RtfAliases Property​

Optional fallback identifiers to probe on paste. Empty when the primary format is the only known identifier on the current OS.

public System.Collections.Generic.IReadOnlyList<Avalonia.Input.DataFormat<byte[]>> RtfAliases { get; set; }