开发者

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

If I display a string too long for a TextBlock it just appears to keep writing past the edge of the TextBlock开发者_如何学Go. 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


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.


Set the TextTrimming property to WordEllipsis.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜