WP7 Autosize TextBlock to Maximum
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 oth开发者_Go百科erwise 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
Maybe the Viewbox was not available in May, but it is available now in November.
Thanks for the hint
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. :(
精彩评论