[英]How many characters can I fit in a control, WP7 Silverlight
I want to take a dynamic string of text, and break it up so that it will fit in one or more textboxes or textblocks.我想获取一个动态的文本字符串,并将其分解,以便它适合一个或多个文本框或文本块。 Preferably textboxes.
最好是文本框。 So let's say I get a string of text thats 132 characters long, but I can only display 40 characters in the textbox before it goes out of view.
因此,假设我得到一个 132 个字符长的文本字符串,但在它消失之前我只能在文本框中显示 40 个字符。 So, I want to break up the text into 4 textboxes.
所以,我想把文本分成 4 个文本框。 I want to find out programatically how many characters can be displayed.
我想以编程方式找出可以显示多少个字符。
I tried ActualWidth, but get 0.0.我试过 ActualWidth,但得到 0.0。
There isn't a way to measure text on the phone.没有办法测量手机上的文本。 If you were only ever going to use a fixed text size you could measure all the characters in advance and calculate accordingly.
如果您只打算使用固定的文本大小,您可以提前测量所有字符并进行相应计算。
However, you may find it easier to use the same method as in http://nerdplusart.com/texttrimming-textblock-for-silverlight to override MeasureOverride and trim the text until it fits.但是,您可能会发现使用与http://nerdplusart.com/texttrimming-textblock-for-silverlight相同的方法来覆盖 MeasureOverride 并修剪文本直到合适为止更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.