在WPF中测量文本 [英] Measuring text in WPF

查看:175
本文介绍了在WPF中测量文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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屋!

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