如何缩小 Textblock 中的字体大小以适应内容的宽度并保持字体纵横比 [英] How to shrink font size in Textblock to fit width of content AND maintain font aspect ratio

查看:112
本文介绍了如何缩小 Textblock 中的字体大小以适应内容的宽度并保持字体纵横比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是交易:我有这行 XAML

Here's the deal: I have this line of 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 也会水平缩放内容,使文本框的宽度变小.举个例子

I want the font to scale down to fit the contents height and width. What happens now is that the font scales down, but the Viewbox also scales the content horizontally, making the width of the textbox smaller. Here's an example

示例图片

如果我设置 Stretch="Fill" 文本将填充宽度,但只缩小高度的字体大小,使字体看起来非常难看 像这样.

If I set Stretch="Fill" the text will fill the widht, but shrinks only font-size in heigth, making the font look horribly ugly Like this.

是否可以缩小文本以适应框架,以便使用容器的整个宽度和高度?

Is it possible to shrink the text to fit inside a frame so that it uses the whole width and height of the container?

推荐答案

您不能将视图框的 StretchDirection 属性设置为DownOnly".此设置导致内容只会被垂直拉伸.

You may not set the StretchDirection property of your viewbox to "DownOnly". This setting leads to the effect that the content only gets stretched vertical.

这篇关于如何缩小 Textblock 中的字体大小以适应内容的宽度并保持字体纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆