WPF ignoring BiDi control characters
Have you ever tried using the following BiDirectional (Disclaimer: The content linked here is not from Microsoft: http://en.wikipedia.org/wiki/Bi-directional_text http://unicode.org/reports/tr9/) control characters in WPF?
- LRM (U+200E, Left-To-Right Mark)
- LRE (U+202A, Left-To-Right Embedding)
- LRO (U+202D, Left-To-Right Override)
- PDF (U+202C, Pop Directional Formatting)
If the answer is yes, you will have noticed that WPF is completely ignoring them. (That is: It is ignoring all except for the LRM mark, which only works when the Language is set to "en-US"!)
Silverlight, on the other hand, does regard them and renders the affected text correctly.
Here is a comparison, first in WPF and then in Silverlight:
I used exactly the same code for both examples. (Please note that I replaced the real BiDi control characters with bold text (e.g. [LRM] ), to avoid confusion and compatibility issues.)
Note how WPF does change the way it treats the LRM character when you set the Language attribute to en-US:
However curious this may seem: This is actually not a bug, but desired behavior!
The reason for the difference is that WPF offers a different, higher-level way of implementing bidirectional text, to enable the implementation of RichText controls. (See here for a detailed guide on BiDi in WPF: http://msdn.microsoft.com/en-us/library/aa350685.aspx
The correct implementation (in WPF) for the example above would look like this:
I hope this was helpful!