RegisterJsObject CefSharp 不起作用

RegisterJsObject CefSharp not work

我在 CefSharp 和 js 通信方面遇到了问题。 这是我的结构。在我的 MainWindow.xaml.cs 中,我有:

chromium = new CefSharp.Wpf.ChromiumWebBrowser();
chromium.RegisterJsObject("jsInterface", new jsMapInterface());

其中 jsMapInterface 是一个 public class 及其方法。

在我的 html/js 文件夹中,我调用了一个 C# 方法:

window.jsInterface.myTest();
//jsInterface.myTest();  //I have tested twice

其中 myTest() 是 jsMapInterface class 中的一个方法,但没有任何反应。我的错误在哪里?

谢谢指教。

尝试在 C# 端使用大写字母,例如 MyTest() 请注意 https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#3-how-do-you-expose-a-net-class-to-javascript

中的

CefSharp 会执行名称修改。原因是它试图鼓励在 JS 端遵循 JS 约定,在该端遵循 C# 约定。

最终从 https://github.com/cefsharp/CefSharp/search?utf8=%E2%9C%93&q=BoundObject

中的示例代码开始工作

嗨,我想我可能会迟到......但一切看起来对我来说都很好......但也许你应该保留 new jsMapInterface() 的模块化参考以确保它不是 destroyed/cleaned向上。