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