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.
精彩评论