Skip to main content

IClipboard Interface

Definition

Assembly:Avalonia.Base
Package:Avalonia

Represents the system clipboard.

public interface IClipboard

Methods

NameDescription
ClearAsyncClears any data from the system clipboard.
FlushAsyncPermanently adds the data that is on the Clipboard so that it is available after the data's original application closes.
SetDataAsyncPlaces a data object on the clipboard. The data object is responsible for providing supported formats and data upon request.
TryGetDataAsyncRetrieves data from the clipboard.
TryGetInProcessDataAsyncRetrieves the exact instance of a Avalonia.Input.IAsyncDataTransfer previously placed on the clipboard by Avalonia.Input.Platform.IClipboard.SetDataAsync(Avalonia.Input.IAsyncDataTransfer), if any.

ClearAsync Method

Clears any data from the system clipboard.

public System.Threading.Tasks.Task ClearAsync()

Returns

System.Threading.Tasks.Task

FlushAsync Method

Permanently adds the data that is on the Clipboard so that it is available after the data's original application closes.

public System.Threading.Tasks.Task FlushAsync()

Returns

System.Threading.Tasks.Task

Remarks

This method is only supported on the Windows platform. This method will do nothing on other platforms.

SetDataAsync Method

Places a data object on the clipboard. The data object is responsible for providing supported formats and data upon request.

public System.Threading.Tasks.Task SetDataAsync(Avalonia.Input.IAsyncDataTransfer dataTransfer)

Parameters

dataTransfer Avalonia.Input.IAsyncDataTransfer

The data object to set on the clipboard.

Returns

System.Threading.Tasks.Task

Remarks

If dataTransfer is null, nothing will get placed on the clipboard and this method will be equivalent to Avalonia.Input.Platform.IClipboard.ClearAsync.

The Avalonia.Input.IAsyncDataTransfer must NOT be disposed by the caller after this call. The clipboard will dispose of it automatically when it becomes unused.

TryGetDataAsync Method

Retrieves data from the clipboard.

public System.Threading.Tasks.Task<Avalonia.Input.IAsyncDataTransfer> TryGetDataAsync()

Returns

System.Threading.Tasks.Task<Avalonia.Input.IAsyncDataTransfer>

Remarks

The returned Avalonia.Input.IAsyncDataTransfer MUST be disposed by the caller.

Avoid storing the returned Avalonia.Input.IAsyncDataTransfer instance for a long time: use it, then dispose it as soon as possible.

TryGetInProcessDataAsync Method

Retrieves the exact instance of a Avalonia.Input.IAsyncDataTransfer previously placed on the clipboard by Avalonia.Input.Platform.IClipboard.SetDataAsync(Avalonia.Input.IAsyncDataTransfer), if any.

public System.Threading.Tasks.Task<Avalonia.Input.IAsyncDataTransfer> TryGetInProcessDataAsync()

Returns

System.Threading.Tasks.Task<Avalonia.Input.IAsyncDataTransfer>

The data transfer object if present, null otherwise.

Remarks

This method cannot be used to retrieve a Avalonia.Input.IAsyncDataTransfer set by another process.

This method is only supported on Windows, macOS and X11 platforms. Other platforms will always return null.

Contrary to Avalonia.Input.Platform.IClipboard.TryGetDataAsync, the returned Avalonia.Input.IAsyncDataTransfer must NOT be disposed by the caller since it's still owned by the clipboard.