Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set textblock or label with resizable font size in WPF?

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?

like image 562
Ershad Avatar asked Feb 28 '23 06:02

Ershad


2 Answers

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>
like image 62
Kyle Rosendo Avatar answered Mar 04 '23 11:03

Kyle Rosendo


The following lines also give the expected result.

<Viewbox>
        <TextBlock TextWrapping="Wrap" Text="Some Text" />
</Viewbox>
like image 28
Sajin Avatar answered Mar 04 '23 09:03

Sajin