在WPF中测量文本 [英] Measuring text in WPF
问题描述
最底层的技巧(因此给出了最佳范围的创意优化)是使用GlyphRuns。
这不是很好的记录,但我写了一个小例子:
http://smellegantcode.wordpress.com/2008/07/03/glyphrun-and-so-forth/
这个例子演示了字符串的长度,作为渲染之前的必要步骤。
Using WPF, what is the most efficient way to measure a large number of short strings? Specifically, I'd like to determine the display height of each string, given uniform formatting (same font, size, weight, etc.) and the maximum width the string may occupy?
The most low-level technique (and therefore giving the most scope for creative optimisations) is to use GlyphRuns.
It's not very well documented but I wrote up a little example here:
http://smellegantcode.wordpress.com/2008/07/03/glyphrun-and-so-forth/
The example works out the length of the string as a necessary step before rendering it.
这篇关于在WPF中测量文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!