0
   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();
    }

上記のサンプル コードでは、web ブラウザーが指定された html5 テキストを含む文字列に移動すると、レンダリングは適切ですが、メタ タグを削除すると、ナビゲーションは正しく、理由を理解できません。

4

1 に答える 1

1

これは、文字列変数で使用されている .NET 文字エンコーディングがUTF-8 ではなく、UTF-16 であるためです。これに関する詳細については、 https://stackoverflow.com/a/1025346/694641を参照してください。

エンコーディングを指定しない場合、ブラウザは実際のテキスト エンコーディングを自動的に自動検出します。

于 2013-04-29T12:57:20.793 に答える