How to grow/shrink a TextBlock (Font Size) to the available space in WPF? How to grow/shrink a TextBlock (Font Size) to the available space in WPF? wpf wpf

How to grow/shrink a TextBlock (Font Size) to the available space in WPF?


The WPF Viewbox control will grow / shrink its contents to the available space:

http://www.wpftutorial.net/ViewBox.html

Just place your TextBlock within a ViewBox:

<Viewbox Stretch="Uniform" Width="50" Height="50">    <TextBlock Text="Test" /></Viewbox>

Of course, your Viewbox is typically scaled by its container, but hopefully you get the idea!