【问题标题】:Awesomium WebControl load stringAwesomium WebControl 加载字符串
【发布时间】:2015-04-04 09:05:30
【问题描述】:

有没有办法在 webControl 中将 html 作为字符串加载?

类似:

webControl.Load("<!DOCTYPE html><html>...");

就像在普通 wpf webControl 中使用的一样:

webControl.NavigateToString("<!DOCTYPE html><html>...");

【问题讨论】:

标签: c# wpf awesomium


【解决方案1】:

实际上,现在我在 Awesomium 站点的 C++ 教程(不在 .net wpf 上)找到了答案。

这是我的解决方案:

 var uri = new Uri("data:text/html,<!DOCTYPE html><html>...", UriKind.Absolute);

            webControl.Source = uri;

【讨论】:

  • 如果 html 字符串太大,此操作会失败。我收到一个错误:Invalid URI: The Uri string is too long.
【解决方案2】:

我知道这是一个老问题,但这是我设法做到的:

var page = new WebControl
{
    ViewType = WebViewType.Window,
};  
page.NativeViewInitialized += (s, e) =>
{
    page.LoadHTML("<html>SOME TEXT</html>");
};

【讨论】:

    【解决方案3】:

    不要在源代码中使用 URL,只需将您的 HTML 放在那里

    Awesomium tutorials加载

    【讨论】:

    • 感谢您为我提供的帮助,但这不是我想要的。
    【解决方案4】:

    这是我的解决方案: 将 html 字符串加载到文件中,然后使用 webControl.Source 属性加载页面。

     public static string WriteHtmlToTempFile(string html)
     {
         var fileName = GetTempFileName("html");
         System.IO.File.WriteAllText(fileName, html);
         return fileName;
    
     }
     var strHtml = "<HTML> Hello World</HTML>";
     var file = Common.WriteHtmlToTempFile(strHtml);
     var wUri = new Uri(string.Format(@"file://{0}", file   ));
     webControl2.Source = wUri;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多