Reputation: 2398
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
}
Upvotes: 3
Views: 1496
Reputation: 11
Maybe the Viewbox was not available in May, but it is available now in November.
Thanks for the hint
Upvotes: 1
Reputation: 65586
The automatic way to do this is with a ViewBox but, unfortunately, this isn't available on the phone.
You'll have to resize the text yourself. :(
Upvotes: 0
Reputation: 5713
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
Upvotes: 1