How to set textblock or label with resizable font size in WPF?

匆匆过客 提交于 2020-02-01 05:06:10

问题


In WPF, if i put any controls in grid, if i resize the grid, it automatically resizes all the controls in it.But in label or textblock or any other text elements, all the control sizes will change but font size remains same, it will not change.

If font has to change as per grid size, What should be done?


回答1:


You can achieve this by using a ViewBox. It will transform (not resize) your font (well, the control) depending on the control size.

Look at this here for more information;

<Viewbox Stretch="Uniform">
    <TextBlock Text="Test" />
</Viewbox>



回答2:


The following lines also give the expected result.

<Viewbox>
        <TextBlock TextWrapping="Wrap" Text="Some Text" />
</Viewbox>


来源:https://stackoverflow.com/questions/1464185/how-to-set-textblock-or-label-with-resizable-font-size-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!