百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

TextCopy

> 编程语言
开源

一个跨平台的包,用于将文本复制到剪贴板和从剪贴板复制文本。

570 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个跨平台的包,用于将文本复制到剪贴板和从剪贴板复制文本。

TextCopy

A cross platform package to copy text to and from the clipboard.

See Milestones for release notes.

NuGet package

https://nuget.org/packages/TextCopy/

Usage

SetTextAsync

cs
await ClipboardService.SetTextAsync("Text to place in clipboard");

snippet source | anchor

SetText

cs
ClipboardService.SetText("Text to place in clipboard");

snippet source | anchor

GetTextAsync

cs
var text = await ClipboardService.GetTextAsync();

snippet source | anchor

GetText

cs
var text = ClipboardService.GetText();

snippet source | anchor

Clearing The Clipboard

cs
ClipboardService.SetText("");

snippet source | anchor

cs
await ClipboardService.SetTextAsync("");

snippet source | anchor

Instance API

In addition to the above static API, there is an instance API exposed:

cs
Clipboard clipboard = new();
clipboard.SetText("Text to place in clipboard");

snippet source | anchor

Dependency Injection

An instance of Clipboard can be injected into IServiceCollection:

cs
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.

Supported on

  • 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
  • Blazor WebAssembly 6.0 and up

Blazor WebAssembly

Due to the dependency on JSInterop the static ClipboardService is not supported on Blazor.

Instead inject an IClipboard:

cs
var builder = WebAssemblyHostBuilder.CreateDefault();
var serviceCollection = builder.Services;
serviceCollection.InjectClipboard();
builder.RootComponents.Add("app");

snippet source | anchor

Then consume it:

cs
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

Linux uses xsel to access the clipboard. As such it needs to be installed and callable.

Icon

Clone designed by Wes Breazell from The Noun Project.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言