How to crop a line with an ellipsis in a Silverlight TextBlock?

If I show a line that is too long for a TextBlock, it just starts writing over the edge of the TextBlock. I would prefer to use the general technique of adding an ellipse ("...") if the text does not fit into the space provided. How do I do this in Silverlight?

All the links I found use the TextRenderer class, which is not available in Silverlight.

+8
c # silverlight
source share
2 answers

You did not say which version of Silverlight is. Assuming Silverlight 4, it baked into a TextBlock through the TextTrimming property.

<TextBlock TextTrimming="WordEllipsis"/> 

The only thing you need to do is make sure that the width of your TextBlock is limited and that you are using NoWrap for TextWrapping .

+14
source share

Set the TextTrimming property for WordEllipsis.

 <TextBlock Text="My long text" TextTrimming="WordEllipsis"/> 
+3
source share

All Articles