public MainPage()
{
InitializeComponent();
WebBrowser test = new WebBrowser();
string tes1t = @"<!DOCTYPE html>
<html>
<head>
<title>Sample Page</title>
<meta charset=""utf-8"">
</head>
<body>
<p>sample html Navigate to string</p>
</body>
</html>";
test.IsScriptEnabled = true;
test.ScriptNotify += test_ScriptNotify;
test.IsHitTestVisible = true;
test.NavigateToString(tes1t);
ContentPanel.Children.Add(test);
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
void test_ScriptNotify(object sender, NotifyEventArgs e)
{
// throw new NotImplementedException();
}
在上面的示例代码中,当webbrowser导航到带有给定html5文本的字符串时,渲染是正确的,但是当我删除元标记时,导航是正确的,无法弄清楚原因
答案 0 :(得分:1)
那是因为你的字符串变量中使用的.NET字符编码是而不是 UTF-8,它是UTF-16。有关此问题的详细讨论,请参阅https://stackoverflow.com/a/1025346/694641。
如果您未指定编码,浏览器将自动为您自动检测实际的文本编码。