开发者

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

开发者 https://www.devze.com 2022-12-09 00:46 出处:网络
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, si

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, s开发者_开发问答o how do I add the usual "..." at the end of the text so as to say there is more to read


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


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"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消