gpt4 book ai didi

c# - wpf 阿拉伯文字显示不正确

转载 作者:行者123 更新时间:2023-11-30 15:09:33 25 4
gpt4 key购买 nike

我想从右到左显示一些阿拉伯文本。所以我将流向设置为从右到左。下面是我的程序:

<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top" >
<TextBlock Margin="104,96,0,0" VerticalAlignment="Top" Height="Auto" Text="(وقت القاعدة الرئيسية 1 (بتوقيت 12 ساعة" HorizontalAlignment="Left" FontSize="20" />
</Grid>

输出似乎不正确。右括号出现在不同的位置。输出为 وقت القاعدو الرئيسيو 1 (بتوقيت 12 ساعة)

请给出建议/解决方案。

最佳答案

问题是,虽然您的代码在 XAML 中“看起来”正确,但第一个字符是“(”,这不是您想要的。您打算将其作为从右到左的字符串的最后一个字符意味着它实际上应该是一个 ')' 字符(但在从右到左的语言中它是镜像的)。

如果您希望您的 XAML 看起来正确并且 WPF 能够正确显示它,您需要更正您的大括号并使用特殊的 unicode 字符 &ux200F;标记字符,以便 XAML 理解最后一个“)”仍然是从右到左。

来自 Wikipedia

In the algorithm, each sequence of concatenated strong characters is called a "run". A weak character that is located between two strong characters with the same orientation will inherit their orientation. A weak character that is located between two strong characters with a different writing direction, will inherit the main context's writing direction (in an LTR document the character will become LTR, in an RTL document, it will become RTL). If a "weak" character is followed by another "weak" character, the algorithm will look at the first neighbouring "strong" character. Sometimes this leads to unintentional display errors. These errors are corrected or prevented with "pseudo-strong" characters. Such Unicode control characters are called marks. The mark (U+200E ‎​ left-to-right mark (HTML: ‎ ‎ LRM) or U+200F ‏​ right-to-left mark (HTML: ‏ ‏ RLM)) is to be inserted into a location to make an enclosed weak character inherit its writing direction.

尝试

<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top" >
<TextBlock Margin="104,96,0,0" VerticalAlignment="Top" Height="Auto" Text="وقت القاعدة الرئيسية 1 (بتوقيت 12 ساعة)‏" HorizontalAlignment="Left" FontSize="20" />
</Grid>

请注意,虽然这看起来一样,但实际上有一个隐藏字符和结束括号不同。

关于c# - wpf 阿拉伯文字显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4373116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com