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.
1
await Application.Current.Clipboard.SetTextAsync("Hello World!");
2
​
3
var text = await Application.Current.Clipboard.GetTextAsync();
Copied!
You can also store objects in the Clipboard but this is not supported on Android and iOS.
1
record Person(string Name, int Age);
2
​
3
var person = new Person("Peter Griffin", 58);
4
​
5
var dataObject = new DataObject();
6
dataObject.Set("my-app-person", person);
7
​
8
await Application.Current.Clipboard.SetDataObjectAsync(dataObject);
9
​
10
var storedPerson = (Person) await clipboard.GetDataAsync("my-app-person");
Copied!
Objects are stored and retrieved with a format string that should be unique to your Application and object type.

Reference

​IClipboard​

Source code

Export as PDF
Copy link
Edit on GitHub