542179528 发表于 2015-5-12 09:44:20

Windows Phone 7 WebBrowser 中文乱码问题

  通过WebBrowser直接请求网页,是正常显示的,只是通过获取到字符串,再通过NavigateToString()就会显示乱码.
  中文转换成 Unicode编码就可以了 :
      public static string Unicode2HTML(string HTML)
      {
              StringBuilder str = new StringBuilder();
              char c;
              for (int i = 0; i < HTML.Length; i++)
              {
                  c = HTML;
                  if (Convert.ToInt32(c) > 127)
                  {
                    str.Append("&#" + Convert.ToInt32(c) + ";");
                  }
                  else
                  {
                    str.Append(c);
                  }
              }
              return str.ToString();
         }
         private void RenderPage()
        {
              var html = FxConstants.ArticleViewTemplate
                  .Replace("{article-header}", _SelectedRssItem.Title)
                  .Replace("{article-content}", _Content)
                  .Replace("{background-specific-style}",
                           PhoneUI.CurrentPhoneBackground == PhoneBackground.Dark
                             ? Fx.Instance.Settings["Article-View-DarkBackground-CSS"]
                             : Fx.Instance.Settings["Article-View-LightBackground-CSS"])
                  .Replace("{common-style}", Fx.Instance.Settings["Article-View-CSS"]);
              html = Unicode2HTML(html);
              Browser.NavigateToString(html);
        }
页: [1]
查看完整版本: Windows Phone 7 WebBrowser 中文乱码问题