WPF TextBlock font resize to fill available space in a Grid

后端 未结 6 1509
醉酒成梦
醉酒成梦 2020-12-08 01:53

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

6条回答
  •  伪装坚强ぢ
    2020-12-08 02:22

    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.

提交回复
热议问题