操作系统:Windows 7
Cef版本: Wpf
大家好,
我正在尝试加载使用 MathQuill 公式编辑器 ( https://pastebin.com/wgnTKcpS ) 的本地 HTML 文件 ( http://mathquill.com )。但是,使用此代码时:
MathQuillBrowser.IsBrowserInitializedChanged += (s, e) =>
{
if (MathQuillBrowser.IsBrowserInitialized)
MathQuillBrowser.LoadHtml(File.ReadAllText(Environment.CurrentDirectory + "/mathquill.html"), "https://somefakeurl-mathquill.com");
};
要将 HTML 文件加载到 ChromiumBrowser
,MathQuill 跨度不会显示在 Wpf 窗口的 ChromiumBrowser
中。我做错了什么?
如何重现问题:
- 在 VS 中创建一个新的 Wpf 应用程序并使用 Nuget 安装 CefSharp
- 进入项目的bin\x86\Debug文件,将上面提到的HTML(在一个名为mathquill.html的文件中)和最新版本的MathQuill放入。
- 创建一个
ChromiumBrowser
控件并将其添加到某个窗口的主控件中。 - 使用上述代码将 Html 加载到
ChromiumBrowser
。
重要说明:上面的 C# 代码适用于(显示 html 元素)不加载外部 CSS 样式表的元素。此外,如果您在 Chrome 等浏览器中打开 html 代码,它会按预期工作。
最佳答案
Cef浏览器不知道CSS文件在哪里,所以找不到。简单的解决方案是使用 CDN(https://cdnjs.com/libraries/mathquill,对于 MathQuill)。
关于c# - 如何将本地 HTML 加载到包含 CSS 样式表的 CefSharp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43195934/