WPF TextBlock字体调整大小以填充网格中的可用空间 [英] WPF TextBlock font resize to fill available space in a Grid

查看:1066
本文介绍了WPF TextBlock字体调整大小以填充网格中的可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本在运行时显示在文本块中。我想
的字体大小是最大的可以是填充
给定的区域。我认为我有正确的文本块设置autosize和
我试图增加字体大小,直到文本块大于
其父然后减少字体大小1.问题是我可以't
得到控制重绘/重新计算它的大小。

是一个更好的方法来做到这一点?或者有什么方法可以让我的方法工作?
$ b $ p $ lt; code>< Grid> $>在$ ViewBox
< Viewbox>
< TextBlock TextWrapping =WrapText =Some Text/>
< / Viewbox>
< / Grid>


I have some text that is displayed at run time in a textblock. I want the font size to be the biggest it can be to fill the area that is given. I think I have the textblock setup correctly to "autosize" and I try to increase the font size till the textblock is bigger than than its parent then decrease the font size by 1. The problem is I can't get the control to redraw/recompute its size.

Is the a better way to do that? Or is there a way I can make my method work?

解决方案

Wrap the TextBlock inside a ViewBox:

   <Grid>
    <Viewbox>
        <TextBlock TextWrapping="Wrap" Text="Some Text" />
    </Viewbox>
   </Grid>

这篇关于WPF TextBlock字体调整大小以填充网格中的可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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