相关疑难解决方法(0)

如何在C#中将数据复制到剪贴板

如何将字符串(例如"hello")复制到C#中的系统剪贴板,所以下次按下CTRL+V我会得到"你好"?

c# clipboard

409
推荐指数
5
解决办法
33万
查看次数

在Xamarin.Forms中编写设备平台特定代码

我有以下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)

c# xamarin.ios xamarin.android xamarin xamarin.forms

22
推荐指数
3
解决办法
3万
查看次数

在异步方法中设置剪贴板

[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。

如何从该异步方法设置剪贴板?

.net c# ole

6
推荐指数
1
解决办法
1665
查看次数