为什么会出错 - 在 dotnetbrowser 中模拟鼠标时?

Why Mistake - when simulate mouse in dotnetbrowser?

但是在构建时 - 调用线程必须是 STA,因为许多 UI 组件首先需要这个 browser.MouseMove(x, y)

public MainWindow()
{
    // Initialize WPF Application UI.

    InitializeComponent();

    // Create WPF BrowserView component.
    browser = BrowserFactory.Create();

    browserView = new WPFBrowserView(browser);
    // Embed BrowserView component into main layout.
    mainLayout.Children.Add(browserView);
    browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
    {
        if (e.IsMainFrame)
        {
            int x = 100;
            int y = 10;
            browser.MouseMove(x, y);
        }
    };

    browserView.Browser.LoadURL("http://google.com");
}

尝试将您的代码包装在 Dispatcher.BeginInvoke 内。

 if (e.IsMainFrame)
 {
      int x = 100;
      int y = 10;
      Dispatcher.BeginInvoke(new Action( ()=> {
          browser.MouseMove(x, y);
       }
 }