WPF TextBlock font resize to fill available space in a Grid?

Up vote 5 down vote favorite 1 share g+ share fb share tw.

I have some text that is displayed at run time in a textblock. I want the font size to be the biggest it can be to fill the area that is given. I think I have the textblock setup correctly to "autosize" and I try to increase the font size till the textblock is bigger than than its parent then decrease the font size by 1.

The problem is I can't get the control to redraw/recompute its size. Is the a better way to do that? Or is there a way I can make my method work?

Wpf fonts resize textblock link|improve this question edited Sep 24 '11 at 18:04Dave Clemmer1,78331030 asked Feb 17 '10 at 16:57Nate Zaugg1,318620 92% accept rate.

Well, its not a "perfect" answer, but this is a quick hack (you can drop this into kaxaml and test it out): The ViewBox will enlarge any content to fill its container. The problem is that the TextBlock, while it sizes to its text, has padding at the top and bottom that you can't get rid of (without doing some heavy lifting). This might get you closer to what you want, tho.

I found a great way to do this using ViewBox: This is some text.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions