如何在 WPF 中的 Web 浏览器控件中显示 unicode 字符 [英] how to display unicode character in web browser control in WPF

查看:36
本文介绍了如何在 WPF 中的 Web 浏览器控件中显示 unicode 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 WPF 的 Web 浏览器控件中显示不同语言的 unicode 字符但它显示特殊字符

I want to display unicode character for different languages in web browser control of WPF but it displays special characters

是否需要在 Web 浏览器控件中进行任何设置?

is there any setting I have to set in web browser control ?

推荐答案

您没有告诉我们您如何将内容加载到 WebBrowser.如果您导航到一个 URL,请确保服务器在 HTTP 响应标头中发送正确的 charset 编码作为 Content-Type 的一部分:

You did not tell us how your load the content into WebBrowser. If you navigate to a URL, make sure the server sends correct charset encoding as part of Content-Typein HTTP response headers:

Content-Type: text/html; charset=utf-8

如果您无法控制服务器,并且服务器没有在响应内容中指定字符集(一种不好的方式),您需要使用 DOM 手动设置编码 document.charset 属性,一旦文档被加载.WebBrowser 的 WPF 版本未公开此属性,因此您需要使用 dynamic:

If you have no control over the server, and the server doesn't specify the charset in the response content (a bad manner), you'd need to manually set the encoding using DOM document.charset property, once the document has been loaded. This property is not exposed by the WPF version of WebBrowser, so you'd need to use dynamic:

dynamic domDocument = webBrowser.Document;
domDocument.charset = "Windows-1252";

我在这里以Windows-1252"为例,如果服务器没有指定,您实际上需要尝试为特定网页找到正确的值.将页面加载到完整的 IE 中,转到查看/编码/更多菜单并找到适合该页面的内容.

I'm using "Windows-1252" as an example here, you'd actually need to experiment to find the correct value for a particular web page, if the server doesn't specify it. Load the page into full IE, go to View/Encoding/More menu and find what works for that page.

也就是说,如果您导航到一个字符串(使用 NavigateToString),它应该支持开箱即用的 Unicode 字符.

That said, if you navigate to a string (with NavigateToString), it should support Unicode characters out-of-the-box.

这篇关于如何在 WPF 中的 Web 浏览器控件中显示 unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆