一个跨平台的包,用于将文本复制到剪贴板和从剪贴板复制文本。
A cross platform package to copy text to and from the clipboard.
See Milestones for release notes.
https://nuget.org/packages/TextCopy/
await ClipboardService.SetTextAsync("Text to place in clipboard");snippet source | anchor
ClipboardService.SetText("Text to place in clipboard");snippet source | anchor
var text = await ClipboardService.GetTextAsync();snippet source | anchor
var text = ClipboardService.GetText();snippet source | anchor
ClipboardService.SetText("");snippet source | anchor
await ClipboardService.SetTextAsync("");snippet source | anchor
In addition to the above static API, there is an instance API exposed:
Clipboard clipboard = new();
clipboard.SetText("Text to place in clipboard");snippet source | anchor
An instance of Clipboard can be injected into IServiceCollection:
serviceCollection.InjectClipboard();snippet source | anchor
The instance should be injected by using IClipboard.
There is also a InjectMockClipboard that injects an instance of MockClipboard with all methods stubbed out.
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");snippet source | anchor
Then consume it:
public partial class IndexModel :
ComponentBase
{
[Inject]
public IClipboard Clipboard { get; set; }
public string Content { get; set; }
public Task CopyTextToClipboard() =>
Clipboard.SetTextAsync(Content);
public async Task ReadTextFromClipboard() =>
Content = await Clipboard.GetTextAsync();
}snippet source | anchor
Blazor support requires the browser APIs clipboard.readText and clipboard.writeText.
Linux uses xsel to access the clipboard. As such it needs to be installed and callable.
Clone designed by Wes Breazell from The Noun Project.
暂无开放 Issues,或尚未同步最近议题。