Is there a way to set the font size of a TextBlock to the maximum allowed for the space available?
Here is a snippet of the code;
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="myText" Text="Grow Me" TextAlignment="Center">
</TextBlock>
</Grid>
</Grid>
I'd like some think like FontSize=Auto|Maximum but they don't exist.
Thanks, Mike
EDIT: Here is the working code;
Thanks for pointing me in the right direction Allen.
while (myText.RenderSize.Width <= 450)
{
myText.FontSize += 1;
myText.UpdateLayout(); //Need this otherwise RenderSize doesn't change
}
you can listen to the outter Grid's SizeChanged event.
Keep incrementing or decrementing your textblock font size until your TextBlock's rendered size is close to outter Grid's size.
Regards, Allen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With