WPF:FlowDirection.RightToLeft如何更改字符串?

Toa*_*ums 8 c# wpf xaml direction

我有一个FormattedText项目.我将flowdirection设置为RightToLeft,我不确定它是如何工作的.它真的不一致地改变了我的字符串.

我想象它只需要一个字符串,并向后显示(通过字符或单词),但在测试中它确实是奇怪的事情.

==================================================

例子,

the string "90%", is displayed as "%90"
Run Code Online (Sandbox Code Playgroud)

为什么%符号从结尾开始?

the string "12 34 56 this is my (string)" 
is displayed as "(this is my (string 56 34 12"
Run Code Online (Sandbox Code Playgroud)

为什么数字会结束,一个括号进入开头并切换方向?

the string "this is a string"
is displayed as "this is a string"
Run Code Online (Sandbox Code Playgroud)

在这种情况下为什么没有发生?

==================================================

我的formattedText看起来像这样:

FormattedText sectionNum = new FormattedText(
   sectNum,
   CultureInfo.CurrentCulture,
   FlowDirection.RightToLeft,
   new Typeface("Verdana"),
   14,
   Brushes.Black);
context.DrawText(sectionNum, new Point(790 - 96, 20));
Run Code Online (Sandbox Code Playgroud)

有谁知道发生了什么?当设置为RightToLeft时,我需要能够显示每个字符串,使其与LeftToRight读取相同.

谢谢!

Art*_*tru 1

TextInfo 有自己的 FlowDirection 并覆盖 WPF FlowDirection。

因此,如果您输入阿拉伯语或希伯来语,它将自动使用“从右到左”的方向。但如果使用符号“;”、“”(空格)就会出现问题。编译器认为它可以是两个方向,并且可以用阿拉伯语表示为“从左到右”,所以这里您应该使用自定义 Wpf FlowDirection。

在您的示例中,编译器了解英文字母并使用“从左到右”的方向,但对空格和数字却很疯狂。

是类似的问题,链接到书中的好部分。