-
Notifications
You must be signed in to change notification settings - Fork 0
IClipboardHandler
Dustin Horne edited this page Mar 5, 2026
·
1 revision
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| 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) |
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