I want to display some Arabic text from Right to Left. So I set the flow direction as RightToLeft. Below is my program:
<Grid x:Name开发者_Go百科="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top" >
<TextBlock Margin="104,96,0,0" VerticalAlignment="Top" Height="Auto" Text="(وقت القاعدة الرئيسية 1 (بتوقيت 12 ساعة" HorizontalAlignment="Left" FontSize="20" />
</Grid>
The output does not seem correct.The close parenthesis is appearing at a different position. the output is وقت القاعدة الرئيسية 1 (بتوقيت 12 ساعة)
Please give suggestions/solutions.
The problem is that while your code 'looks' correct in XAML the first character is a '(' which isn't what you intend. You intend for this to be the last character of a right-to-left string which means it should really be a ')' character (but in right-to-left languages its mirrored).
If you want your XAML to look right and WPF to display it correctly you need correct your brace and at a special unicode character &ux200F; marker character so that the XAML understands that the last ')' is still right-to-left.
From 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.
Try
<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>
Note that while this looks the same, theres actually a hidden character and the ending parenthesis are different.
精彩评论