使用WPF网络浏览器以及带有斜体标签和阿拉伯文本的HTML时会出现奇怪的字符

问题描述 投票:1回答:1

我不知道这个,但是我在下面做了一个简单的演示。在IE或Edge中查看此页面时,它将正确呈现。我尝试了不同的编码,例如utf-16,Windows-1252,但没有用。在我看来,WebBrowser控件存在问题。有人可以弄清楚吗?// html

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <p><i>اتفاقية</i></p>
    <p>اتفاقية</p>
</body>
</html>

//。xaml页面

<Page x:Class="WpfApp1.LayoutTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Background="Yellow"
    d:DesignHeight="450" d:DesignWidth="800"
    Loaded="Page_Loaded"
    Title="LayoutTest">
    <WebBrowser x:Name="MyWebBrowser" Margin="20,5,0,5"/>
</Page>

//后面的代码

namespace WpfApp1
{
    public partial class LayoutTest : Page
    {
        public LayoutTest()
        {
            InitializeComponent();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            string dirPath = AppDomain.CurrentDomain.BaseDi‌rectory;
            string fileName = "ArabicPage.html";
            string filename = Path.GetFullPath(Path.Combine(dirPath, fileName));
            string content = File.ReadAllText(fileName, Encoding.UTF8);
            MyWebBrowser.NavigateToString(content);
        }
    }
}

//结果(没有标签的结果正确)

enter image description here

//在普通浏览器中(边缘)

enter image description here

更新:

我已经使用UWP Webview测试了它,并且在那里可以正常工作。

c# .net wpf localization webbrowser-control
1个回答
0
投票

您可以通过使用正确支持阿拉伯字符的字体来避免这种情况,例如Tahoma:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body style = "font-family:Tahoma,serif">
    <p><i style = "font-size:26px;">اتفاقية</i></p>
    <p style = "font-size:26px;">اتفاقية</p>
</body>
</html>

© www.soinside.com 2019 - 2024. All rights reserved.