You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -95,6 +97,19 @@ clipboard.SetText("Text to place in clipboard");
95
97
<!-- endsnippet -->
96
98
97
99
100
+
### Dependency Injection
101
+
102
+
An instance of `IClipboard` can be injected into `IServiceCollection`:
103
+
104
+
<!-- snippet: InjectClipboard -->
105
+
<aid='snippet-injectclipboard'/></a>
106
+
```cs
107
+
serviceCollection.InjectClipboard();
108
+
```
109
+
<sup><ahref='/src/BlazorSample/Program.cs#L16-L18'title='File snippet `injectclipboard` was extracted from'>snippet source</a> | <ahref='#snippet-injectclipboard'title='Navigate to start of snippet `injectclipboard`'>anchor</a></sup>
110
+
<!-- endsnippet -->
111
+
112
+
98
113
## Supported on
99
114
100
115
* Windows with .NET Framework 4.6.1 and up
@@ -107,9 +122,57 @@ clipboard.SetText("Text to place in clipboard");
107
122
* Xamarin.Android 9.0 and up
108
123
* Xamarin.iOS 10.0 and up
109
124
* Universal Windows Platform version 10.0.16299 and up
125
+
* Blazor WebAssembly
126
+
127
+
128
+
## Blazor WebAssembly
129
+
130
+
Due to the dependency on `JSInterop` the static `ClipboardService` is not supported on Blazor.
<sup><ahref='/src/BlazorSample/Program.cs#L13-L20'title='File snippet `blazorstartup` was extracted from'>snippet source</a> | <ahref='#snippet-blazorstartup'title='Navigate to start of snippet `blazorstartup`'>anchor</a></sup>
143
+
<!-- endsnippet -->
144
+
145
+
Then consume it:
146
+
147
+
<!-- snippet: Inject -->
148
+
<aid='snippet-inject'/></a>
149
+
```cs
150
+
publicpartialclassIndexModel :
151
+
ComponentBase
152
+
{
153
+
[Inject]
154
+
publicIClipboardClipboard { get; set; }
155
+
156
+
publicstringContent { get; set; }
157
+
158
+
publicTaskCopyTextToClipboard()
159
+
{
160
+
returnClipboard.SetTextAsync(Content);
161
+
}
162
+
163
+
publicasyncTaskReadTextFromClipboard()
164
+
{
165
+
Content=awaitClipboard.GetTextAsync();
166
+
}
167
+
}
168
+
```
169
+
<sup><ahref='/src/BlazorSample/Pages/IndexModel.cs#L9-L28'title='File snippet `inject` was extracted from'>snippet source</a> | <ahref='#snippet-inject'title='Navigate to start of snippet `inject`'>anchor</a></sup>
170
+
<!-- endsnippet -->
171
+
172
+
Blazor support requires the browser APIs [clipboard.readText](https://caniuse.com/#feat=mdn-api_clipboard_readtext) and [clipboard.writeText](https://caniuse.com/#feat=mdn-api_clipboard_writetext).
110
173
111
174
112
-
## Notes on Linux
175
+
## Linux
113
176
114
177
Linux uses [xclip](https://github.com/astrand/xclip) to access the clipboard. As such it needs to be installed and callable.
Copy file name to clipboardExpand all lines: readme.source.md
+24-1Lines changed: 24 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,13 @@ In adition to the above static API, there is an instance API exposed:
46
46
snippet: SetTextInstance
47
47
48
48
49
+
### Dependency Injection
50
+
51
+
An instance of `IClipboard` can be injected into `IServiceCollection`:
52
+
53
+
snippet: InjectClipboard
54
+
55
+
49
56
## Supported on
50
57
51
58
* Windows with .NET Framework 4.6.1 and up
@@ -58,9 +65,25 @@ snippet: SetTextInstance
58
65
* Xamarin.Android 9.0 and up
59
66
* Xamarin.iOS 10.0 and up
60
67
* Universal Windows Platform version 10.0.16299 and up
68
+
* Blazor WebAssembly
69
+
70
+
71
+
## Blazor WebAssembly
72
+
73
+
Due to the dependency on `JSInterop` the static `ClipboardService` is not supported on Blazor.
74
+
75
+
Instead inhect an `IClipboard`:
76
+
77
+
snippet: BlazorStartup
78
+
79
+
Then consume it:
80
+
81
+
snippet: Inject
82
+
83
+
Blazor support requires the browser APIs [clipboard.readText](https://caniuse.com/#feat=mdn-api_clipboard_readtext) and [clipboard.writeText](https://caniuse.com/#feat=mdn-api_clipboard_writetext).
61
84
62
85
63
-
## Notes on Linux
86
+
## Linux
64
87
65
88
Linux uses [xclip](https://github.com/astrand/xclip) to access the clipboard. As such it needs to be installed and callable.
0 commit comments