如何在WPF中设置可调整字体大小的文本块或标签?
问题描述:
在WPF中,如果我在网格中放置任何控件,如果我调整网格的大小,它会自动调整其中所有控件的大小,但是在label或textblock或任何其他文本元素中,所有控件的大小都会改变,但字体大小仍然保持不变一样,它不会改变.
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?
答
您可以使用ViewBox
来实现.它将根据控件的大小变换(而不是调整控件的大小)字体.
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>