我如何用截断在Silverlight的TextBlock省略号一个字符串? [英] How do I truncate a string with an ellipsis in a Silverlight TextBlock?

查看:146
本文介绍了我如何用截断在Silverlight的TextBlock省略号一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我显示字符串太长TextBlock的,它只是似乎继续写过去TextBlock的边缘。我宁愿用它添加一个省略号(...)如果文本是不会以适应所提供的空间的常用技术。我应该如何去在Silverlight这样做呢?

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?

我发现所有引用使用TextRenderer类这不是在Silverlight中可用

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

推荐答案

您没有说哪个版本的Silverlight,这是。假设Silverlight 4中,它通过的 TextTrimming 财产

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

<TextBlock TextTrimming="WordEllipsis"/>

您需要做的唯一的事情就是确保您的TextBlock的宽度适当限制,您使用<一个HREF =http://msdn.microsoft.com/en-us/library/system.windows.textwrapping%28v=vs.95%29.aspx> NoWrap的获得的TextWrapping

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

这篇关于我如何用截断在Silverlight的TextBlock省略号一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆