事情是这样的:我有这行 XAML
<Viewbox Canvas.Left="27" Canvas.Top="479" Width="377" Height="21" Stretch="Fill"
StretchDirection="DownOnly" VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBlock Name="TitleText" TextWrapping="Wrap" TextAlignment="Left" FontSize="14"
FontStretch="Normal" FontStyle="Normal" Foreground="White" Width="377" >some long text here
</TextBlock>
</Viewbox>
我希望字体缩小以适应内容的高度和宽度。 现在发生的情况是字体缩小了,但 Viewbox 也水平缩放内容,使文本框的宽度变小。 这是一个例子
如果我设置 Stretch="Fill",文本将填充宽度,但仅缩小高度中的字体大小,使字体看起来非常难看 Like this 。
是否可以缩小文本以适合框架,以便它使用容器的整个宽度和高度?
最佳答案
继续 Marcus 的工作:
<Viewbox Canvas.Left="27" Canvas.Top="479" Width="377" Height="21" Stretch="Fill"
StretchDirection="DownOnly" VerticalAlignment="Top" HorizontalAlignment="Left">
<Viewbox Stretch="Fill" Width="Auto" Height="Auto">
<TextBlock Name="TitleText" TextWrapping="Wrap" TextAlignment="Left" FontSize="14"
FontStretch="Normal" FontStyle="Normal" Foreground="White" Width="377" >some long text here
</TextBlock>
</Viewbox>
</Viewbox>
我把它改成了
Stretch="Uniform"
和
StretchDirection="Both"
结果看起来很棒,没有垂直拉伸(stretch)单词。
关于c# - 如何缩小文本 block 中的字体大小以适应内容的宽度并保持字体纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18638968/