Fredrick
Fredrick

Reputation: 513

How to Text wrap and add ... at the end

Lets say you have this text

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna."

put in a textblock with TextWrapping="Wrap", the textblock only supports 2 lines, so how do I add the usual "..." at the end of the text so as to say there is more to read

Upvotes: 1

Views: 341

Answers (2)

John
John

Reputation: 857

This question has been correctly answered here: How do I truncate a string with an ellipsis in a Silverlight TextBlock?

Silverlight 4 supports the TextTrimming property for TextBlock controls.

<TextBlock TextTrimming="WordEllipsis"/>

Upvotes: 0

Abel
Abel

Reputation: 57149

This is not trivial to answer for use in SilverLight because you cannot use native Win32 methods (of which some methods support ellipsis). There are a few resources on the Net, which basically come down to one of two approaches:

  1. Do-it-yourself calculation, here's a ready made class, you may need to alter it a bit to work with more then one line: http://www.codeproject.com/KB/cs/AutoEllipsis.aspx
  2. Use TextRenderer.DrawText, not sure if that's available or useful in your scenario: http://www.switchonthecode.com/tutorials/how-to-auto-ellipse-text-in-csharp

Upvotes: 2

Related Questions