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

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

问题描述

我有一些文本在运行时显示在文本块中.我想字体大小是可以填充的最大区域给.我想我正确设置了文本块以自动调整大小"和我尝试增加字体大小,直到文本块大于它的父级然后将字体大小减小 1.问题是我不能获取重绘/重新计算其大小的控件.

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?

推荐答案

TextBlock 包裹在 ViewBox 中:

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

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

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