How to resize the font size - WPF?

0

The following code works with winforms :

while (label1.Width < System.Windows.Forms.TextRenderer.MeasureText(label1.Text,
    new Font(label1.Font.FontFamily, label1.Font.Size, label1.Font.Style)).Width)
{
    label1.Font = new Font(label1.Font.FontFamily, label1.Font.Size - 0.5f, label1.Font.Style);
}

How can I do this in WPF? The idea is to make a autoresize in textbox to fit all words.

The following image, which was cut in the last line, I want to decrease the font size until all the words are shown.

The above photo is not a label , it is a textbox .

Any ideas on what to do in WPF?

    
asked by anonymous 21.02.2018 / 19:40

1 answer

1

You can use a ViewBox to auto resize the font size.

Example

<Viewbox>
     <TextBox Text="TESTE"/>
</Viewbox>
    
28.03.2018 / 20:26