How to Text wrap and add … at the end

不想你离开。 提交于 2019-12-24 15:38:32

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/1565953/how-to-text-wrap-and-add-at-the-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!