Skip to main content
Version: 0.10.x

Clipboard

Avalonia provides access to the Clipboard via the IClipboard interface. You can get an instance of this interface for the current Application with Application.Current.Clipboard.

await Application.Current.Clipboard.SetTextAsync("Hello World!");

var text = await Application.Current.Clipboard.GetTextAsync();

You can also store objects in the Clipboard but this is not supported on Android and iOS.

record Person(string Name, int Age);

var person = new Person("Peter Griffin", 58);

var dataObject = new DataObject();
dataObject.Set("my-app-person", person);

await Application.Current.Clipboard.SetDataObjectAsync(dataObject);

var storedPerson = (Person) await clipboard.GetDataAsync("my-app-person");

Objects are stored and retrieved with a format string that should be unique to your Application and object type.

Reference

IClipboard

Source code