Skip to content

IClipboardHandler

Dustin Horne edited this page Mar 5, 2026 · 1 revision

IClipboardHandler

Namespace: ParentElement.RichText.Core.Abstractions.IO

Platform clipboard abstraction. Implement this interface using your target framework's clipboard API (Avalonia, MAUI, WPF, etc.) and pass the implementation to the DocumentController constructor.

public interface IClipboardHandler

Methods

Method Returns Description
GetTextAsync() Task<string?> Retrieve plain text from the clipboard, or null if none is available
SetTextAsync(string) Task Place plain text onto the clipboard
GetImageDataAsync() Task<byte[]?> Retrieve PNG image bytes from the clipboard, or null if none is available
SetRichDataAsync(IReadOnlyList<ContentBlock>, string?) Task Set HTML + RTF rich-text data alongside a plain-text fallback
SetImageBytesAsync(byte[]) Task Set clipboard data for an image-only selection (PNG bytes)

Implementation Guide

public class AvaloniaClipboard : IClipboardHandler
{
    private readonly IClipboard _clipboard;

    public AvaloniaClipboard(IClipboard clipboard) => _clipboard = clipboard;

    public async Task<string?> GetTextAsync()
        => await _clipboard.GetTextAsync();

    public async Task SetTextAsync(string text)
        => await _clipboard.SetTextAsync(text);

    public Task<byte[]?> GetImageDataAsync()
        => Task.FromResult<byte[]?>(null); // extend with platform image support

    public async Task SetRichDataAsync(IReadOnlyList<ContentBlock> blocks, string? plainText)
    {
        // Serialize blocks to HTML/RTF and write to platform clipboard
        await _clipboard.SetTextAsync(plainText ?? string.Empty);
    }

    public Task SetImageBytesAsync(byte[] pngData)
        => Task.CompletedTask; // extend with platform image clipboard
}

See also: IDocumentController · Content-Model

Clone this wiki locally