WPF 中的双向行为不正确?
在 WPF 中设置“语言”属性时遇到奇怪的事情:
- 在窗口或文本框/文本块上将 FlowDirection 设置为“RightToLeft”
- 将语言属性设置为“fa-IR”
- 将文本设置为以下之一下面的示例文本 (A, B)
A.此文本在 WPF 3.5 中无法正确呈现:
链接:+44 1908 215040
它适用于 WinForms 和 Silverlight。请注意,它包含“从左到右标记”(U+200E)
以下是上述内容的 HTML 版本,其中包含对 LRM 的数字字符引用,以可视化 LRM 的插入位置:
فاکس: ‎+44 1908 215040
B.此文本在 WPF 中正确呈现:
فзез: +44 1908 210210
但它包含(我相信)不必要的 LRM 字符。我以反复试验的方式将文本组合在一起。
这是带有额外 LRM 字符的 HTML 版本
فاکس: ‎+‎44‎ ‎1908‎ ‎215040‎
为什么需要额外字符/我对原始文本做错了什么?
注意:如果在 XAML 或代码中显式设置 Language 属性(如 Language="fa-IR")或通过覆盖代码中 Language 属性的默认值(假设当前区域性为“fa-”),则会出现问题。 IR") 如下:
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
如果我将语言属性保留为 en-US,则文本会在 WPF 中正确呈现,但我确实需要设置语言才能进行值转换,而无需在每个属性上显式设置 ConverterCulture以及每个可以绑定到的数据绑定一些与文化相关的数据。
还有其他问题,例如 LRO(“从左到右覆盖”(U+202D))被忽略。
我真的需要帮助了解正在发生的事情,因为这可能会成为将我的应用程序本地化为波斯语和阿拉伯语的障碍。
我怀疑我是做错事的人,因为我没有通过谷歌搜索这个问题。 这是一篇关于 MS Connect 的相关帖子,但迄今为止没有人确认该行为是一个错误:
http://connect.microsoft.com/WPF/feedback/details/682784/in Correct-unicode-bidi-behaviour#
注意:我对 BiDi 算法总体不太熟悉,对 WPF 中的实际实现了解更少。我对 Unicode 有基本的了解。
I experience strange things when setting the "Language" property in WPF:
- Set FlowDirection to "RightToLeft" on a Window or textbox/textblock
- Set the Language property to "fa-IR"
- Set the text to one of the sample texts below (A, B)
A. This text does not render correctly in WPF 3.5:
فاکس: +44 1908 215040
It works with WinForms and Silverlight. Note that it contains a 'LEFT-TO-RIGHT MARK' (U+200E)
Here is a HTML version of the above with numeric character references to LRM, to visualize where the LRM is inserted:
فاکس: +44 1908 215040
B. This text does render correctly in WPF:
فاکس: +44 1908 210210
But it contains (I believe) unncessary LRM characters. I put together the text in a trial-and-error fashion.
Here is the HTML version with the extra LRM characters
فاکس: +44 1908 215040
Why are the extra characters needed / what am I doing wrong with the original text?
Note: The problem occurs IFF setting the Language property, either explicitly in XAML or code (like Language="fa-IR") or by overriding the default value of the Language property in code (assuming current culture being "fa-IR") as so:
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
If I leave the language property as en-US, the text renders correctly in WPF, but I really need to set the Language to have value conversions work without having to set the ConverterCulture explicitly on each and every data binding that could be binding to some culture dependent data.
There are also other problems, like LRO ('LEFT-TO-RIGHT OVERRIDE' (U+202D)) being ignored.
I really need help understanding what is going on, as this could turn out to be a show stopper for localizing my application to Persian and Arabic.
I suspect that I am the one doing something wrong, as I fail to google for the problem.
Here is a a related post on MS Connect, but no one has so far confirmed the behaviour as a bug:
http://connect.microsoft.com/WPF/feedback/details/682784/incorrect-unicode-bidi-behaviour#
Note: I am not that familiar with the BiDi algorithm in general and know even less of the actual implementation in WPF. I have a basic understanding of Unicode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论