post icon

Silverlight Tip of the Day #32 – BiDi – Bi-Directional Text

BiDi or Bi-directional text is text that flows right-to-left (RTL) and left-to-right (LTR). For example, while English flows left to right other languages such as Arabic, Hebrew and Persian scripts flow right to left. Chinese characters can also be written in either RTL or LTR directions.

Silverlight supports BiDi through a property called FlowDirection. This property can be set to either RightToLeft or the default LeftToRight.

The following code below demonstrates this property in action:

<TextBlock FlowDirection="RightToLeft" Text="نصائح Silverlight من اليوم"/>
<TextBlock FlowDirection="RightToLeft" Text="Silverlight 每日提示"/>
<TextBlock FlowDirection="LeftToRight" Text="Silverlight Tips of the Day"/>

 

The first two TextBlocks flow RTL and the last one flows LTR.

Demo:

[silverlight: Tip32_BIDI.xap]

Note that this property can also be applied to other controls such as RichTextBox, ListBox, TextBox, etc.

Source: Tip32_BIDI.zip

Thanks,

–Mike

1 Comment

Leave a comment
  1. Elena Lidin
    13. Aug, 2010 at 4:15 pm #

    Hi Mike,
    There are more problems with LTR or RTL, then just a applying one direction for sentence.
    The real problems starts when sentence contains combination of LTR and RTL. Case, when Hebrew text contains numbers can be perfect sample for this case.
    ASP pages where already tested for long time, and “kinda” have a solution for this problem (even this remain a very buggy area).
    How is Silverlight dealing with this issue?