bClipboard is a Blazor library that simplifies clipboard operations in your Blazor applications. With bClipboard, developers can easily copy text to and read text from the clipboard using simple and intuitive APIs. This library leverages JavaScript interop to provide seamless clipboard functionality within Blazor.
$ dotnet add package bClipboard
bClipboard is a Blazor library that simplifies clipboard operations for Blazor applications. It provides methods to copy text to and read text from the clipboard using JavaScript interop.
To install bClipboard, you need to add the NuGet package to your Blazor project:
dotnet add package bClipboard
In your Program.cs file, register the ClipboardService with the dependency injection container.
[...]
using bClipboard.Extensions;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddBClipboardService();
await builder.Build().RunAsync();
Inject the IClipboardService into your Blazor component and use its methods to copy to and read from the clipboard.
@page "/clipboard"
@inject IClipboardService ClipboardService
<h3>Clipboard Example</h3>
<input @bind="textToCopy" placeholder="Enter text to copy" />
<button @onclick="CopyToClipboard">Copy Text</button>
<p>Clipboard Content: @clipboardContent</p>
<button @onclick="ReadFromClipboard">Read Clipboard</button>
@code {
private string textToCopy;
private string clipboardContent;
private async Task CopyToClipboard()
{
await ClipboardService.CopyToClipboardAsync(textToCopy);
}
private async Task ReadFromClipboard()
{
clipboardContent = await ClipboardService.ReadFromClipboardAsync();
}
}
The library uses a JavaScript file (bclipboard.js) for clipboard operations.
We welcome contributions! Please see our contributing guidelines for more details.