积极答复者
TextBlock在固定大小的情况下改变显示的字体大小如何动态计算它能显示多少字?

问题
答案
-
--> 我想知道该怎么解决让textblock在固定的大小下,显示适合的字数。
看了你这个需求,我依然困惑。不太清楚你到底想教textblock做一个什么样的事情。
1) 你是想让TextBlock开始显示800字,然后当改变字体的时候,你想让Textblock宽度不变,高度变大,依然显示800字?
2) 你是想让Textblock字体改变的时候,比如字体变大了,你是想让Textblock只显示少一点的字数? 比如700字?
我给你几个方法,你可以试试,看看能不能给你什么启示,然后解决你的问题。
1 参考一下“ClipToBounds” 属性。
2 参考一下“TextTrimming” 属性。
3 你可以考虑当改变字体的时候,对Textblock的内容重新加载、
我希望你能讲你的问题描述清楚,这样大家才能针对你的问题为你提供解决方案。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年4月25日 8:52
全部回复
-
我不是很清楚你的这个描述:
--> 这样就导致了经常TextBlock超出panel的大小显示不全,
你能提供一些测试代码么?
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
测试下来并没有出现超出panel的问题,我怀疑是不是因为你并没有指定textblock宽度的原因。
<Grid> <TextBlock TextWrapping="Wrap" Width="500"> Long time ago,There was a temple in a mountain, and an old monk lived there. One day, a young monk came to the temple. The old monk told the little monk that:Long time ago ,There was a temple in a mountain... </TextBlock> </Grid>
-
是的,如果你没有指定textblock的宽带,而且也没有让container(panel)剪切边界的话,textblock会超出边界的。
根据你的描述,我不是很清楚你问题的状态,如果你问题依然存在,能描述一下你现在存在的问题是什么?
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
--> 我想知道该怎么解决让textblock在固定的大小下,显示适合的字数。
看了你这个需求,我依然困惑。不太清楚你到底想教textblock做一个什么样的事情。
1) 你是想让TextBlock开始显示800字,然后当改变字体的时候,你想让Textblock宽度不变,高度变大,依然显示800字?
2) 你是想让Textblock字体改变的时候,比如字体变大了,你是想让Textblock只显示少一点的字数? 比如700字?
我给你几个方法,你可以试试,看看能不能给你什么启示,然后解决你的问题。
1 参考一下“ClipToBounds” 属性。
2 参考一下“TextTrimming” 属性。
3 你可以考虑当改变字体的时候,对Textblock的内容重新加载、
我希望你能讲你的问题描述清楚,这样大家才能针对你的问题为你提供解决方案。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年4月25日 8:52