通過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[i];
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);
}