如何将字符串(例如"hello")复制到C#中的系统剪贴板,所以下次按下CTRL+V我会得到"你好"?
我有以下Xamarin.Forms.ContentPage类结构
public class MyPage : ContentPage
{
public MyPage()
{
//do work to initialize MyPage
}
public void LogIn(object sender, EventArgs eventArgs)
{
bool isAuthenticated = false;
string accessToken = string.Empty;
//do work to use authentication API to validate users
if(isAuthenticated)
{
//I would to write device specific code to write to the access token to the device
//Example of saving the access token to iOS device
NSUserDefaults.StandardUserDefaults.SetString(accessToken, "AccessToken");
//Example of saving the access token to Android device …Run Code Online (Sandbox Code Playgroud) [STAThread]
static void Main(string[] args)
{
DoThing().Wait();
}
static async Task DoThing()
{
Clipboard.SetText("hi");
}
Run Code Online (Sandbox Code Playgroud)
我[STAThread]首先添加了 bc 我收到了这个错误
ThreadStateException:在进行 OLE 调用之前,当前线程必须设置为单线程单元 (STA) 模式
但我仍然遇到同样的错误。
剪贴板来自System.Windows.Forms。
如何从该异步方法设置剪贴板?