Clipboard
Tip
This article covers Uno-specific information for Clipboard. For a full description of the feature and instructions on using it, see Copy and paste.
- The
Windows.ApplicationModel.DataTransfer.Clipboardclass allows you to copy content from your application, and paste the content into your application.
Supported features
| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
|---|---|---|---|---|---|---|---|
SetContent |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
GetContent |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
Clear |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
ContentChanged |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
Flush |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
Using Clipboard with Uno
SetContentandGetContentAPIs currently support textual data on all platforms. On Android, they also support URI and HTML formats, but the clipboard can hold only one item. Setting multiple items at once does not work reliably.ContentChangedevent can observe clipboard changes only when the application is in the foreground. On macOS, theContentChangedevent checks for clipboard changes by polling the currentNSPasteboardchange count in 1-second intervals. The polling starts only after the first subscriber attaches to theContentChangedevent and stops after the last subscriber unsubscribes.Flushoperation has an empty implementation. In contrast to WinUI, on other platforms, data automatically remains in the clipboard even after the application is closed.
Examples
Copying text to clipboard
var dataPackage = new DataPackage();
dataPackage.SetText("Hello, clipboard");
Clipboard.SetContent(dataPackage);
Pasting text from the clipboard
var content = Clipboard.GetContent();
var text = await content.GetTextAsync();
Observing clipboard changes
Clipboard.ContentChanged += Clipboard_ContentChanged;
private void Clipboard_ContentChanged(object sender, object e)
{
// ...
}