How do I truncate a string with an ellipsis in a Silverlight TextBlock?

£可爱£侵袭症+ 提交于 2019-12-23 07:56:14

问题


If I display a string too long for a TextBlock it just appears to keep writing past the edge of the TextBlock. I'd rather it use the common technique of adding an ellipsis ("...") if the text is not going to fit in the space provided. How should I go about doing this in Silverlight?

The references I've found all use the TextRenderer class which is not available in Silverlight


回答1:


You didn't say which Silverlight version this is. Assuming Silverlight 4, it's baked into TextBlock via the TextTrimming property.

<TextBlock TextTrimming="WordEllipsis"/>

The only thing you have to do is make sure your TextBlock's width is properly restricted and you use NoWrap for TextWrapping.




回答2:


Set the TextTrimming property to WordEllipsis.

<TextBlock Text="My long text" TextTrimming="WordEllipsis"/>


来源:https://stackoverflow.com/questions/7327704/how-do-i-truncate-a-string-with-an-ellipsis-in-a-silverlight-textblock

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