A cross platform package to copy text to and from the clipboard.
Support is available via a Tidelift Subscription.
- Usage
- Clearing The Clipboard
- Instance API
- Supported on
- Blazor WebAssembly
- Linux
- Security contact information
https://nuget.org/packages/TextCopy/
await ClipboardService.SetTextAsync("Text to place in clipboard");
ClipboardService.SetText("Text to place in clipboard");
var text = await ClipboardService.GetTextAsync();
var text = ClipboardService.GetText();
ClipboardService.SetText("");
await ClipboardService.SetTextAsync("");
In addition to the above static API, there is an instance API exposed:
var clipboard = new Clipboard();
clipboard.SetText("Text to place in clipboard");
An instance of Clipboard
can be injected into IServiceCollection
:
serviceCollection.InjectClipboard();
The instance should be injected by using IClipboard
.
There is also a InjectMockClipboard
that injects an instance of MockClipboard
with all methods stubbed out.
- Windows with .NET Framework 4.6.1 and up
- Windows with .NET Core 2.0 and up
- Windows with Mono 5.0 and up
- OSX with .NET Core 2.0 and up
- OSX with Mono 5.20.1 and up
- Linux with .NET Core 2.0 and up
- Linux with Mono 5.20.1 and up
- Xamarin.Android 9.0 and up
- Xamarin.iOS 10.0 and up
- Universal Windows Platform version 10.0.16299 and up
- Blazor WebAssembly
Due to the dependency on JSInterop
the static ClipboardService
is not supported on Blazor.
Instead inject an IClipboard
:
var builder = WebAssemblyHostBuilder.CreateDefault();
var serviceCollection = builder.Services;
serviceCollection.InjectClipboard();
builder.RootComponents.Add<App>("app");
Then consume it:
public partial class IndexModel :
ComponentBase
{
[Inject]
public IClipboard Clipboard { get; set; }
public string Content { get; set; }
public Task CopyTextToClipboard()
{
return Clipboard.SetTextAsync(Content);
}
public async Task ReadTextFromClipboard()
{
Content = await Clipboard.GetTextAsync();
}
}
Blazor support requires the browser APIs clipboard.readText and clipboard.writeText.
Linux uses xclip to access the clipboard. As such it needs to be installed and callable.
To report a security vulnerability, use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
Clone designed by Wes Breazell from The Noun Project.