1 0 Tag Archives: text
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:

Install Microsoft Silverlight

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

Source: Tip32_BIDI.zip

Thanks,

–Mike

Leave a Comment
post icon

Silverlight Tip of the Day #28 – Text Trimming

With Silverlight 4 came support for Text Trimming. Text Trimming is a feature that applies to TextBlocks and is used to append “…” at the end of the string if the text in the TextBlock does not fit. In WPF this can be done at the character level or the word level. Silverlight 4 only supports trimming at the word level.

To set it simply set the property TextTrimming to “WordEllipsis” like this:

<TextBlock x:Name="TitleTB" TextTrimming="WordEllipsis"/>

Programmatically it would be done like this:

TitleTB.TextTrimming = TextTrimming.WordEllipsis;

So say I have a TextBlock set to the following string:

“This string is too long to fit here but you can append … by using the property TextTrimming”

Without Trimming it would look like this (notice the word TextTrimming is just missing):

image

With Trimming “…” is appended letting you know there is more text:

image

Thanks,
–Mike

Leave a Comment