How to set textblock or label with resizable font

2020-07-17 05:46发布

In WPF, if i put any controls in grid, if i resize the grid, it automatically resizes all the controls in it.But in label or textblock or any other text elements, all the control sizes will change but font size remains same, it will not change.

If font has to change as per grid size, What should be done?

2条回答
Juvenile、少年°
2楼-- · 2020-07-17 06:00

You can achieve this by using a ViewBox. It will transform (not resize) your font (well, the control) depending on the control size.

Look at this here for more information;

<Viewbox Stretch="Uniform">
    <TextBlock Text="Test" />
</Viewbox>
查看更多
仙女界的扛把子
3楼-- · 2020-07-17 06:05

The following lines also give the expected result.

<Viewbox>
        <TextBlock TextWrapping="Wrap" Text="Some Text" />
</Viewbox>
查看更多
登录 后发表回答