[英]How to make the text's fontsize auto fit its container?
In my Wpf prroject, a TextBlock is used to show app title.在我的 Wpf 项目中,TextBlock 用于显示应用程序标题。 And to support multiple languages, the text is associated with a resource.
为了支持多种语言,文本与资源相关联。
While the TextBlock's parent UI container's size is fixed.而 TextBlock 的父 UI 容器的大小是固定的。 And for different language, the app title's size might differ a lot.
对于不同的语言,应用标题的大小可能会有很大差异。
In below code the font size of the Text is fixed to 20, that will cause UI problem when in some language.在下面的代码中,Text 的字体大小固定为 20,这在使用某些语言时会导致 UI 问题。 How to make the font size auto fit?
如何使字体大小自动适应? Any idea?
任何想法?
<Border Grid.Row="0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="{DynamicResource OCR.OCRWindow.TitleBorder}">
<Grid Name="OCRTitleBar" Background="{DynamicResource OCR.OCRWindow.TitleBar}">
<TextBlock Text="{x:Static prop:Resources.AppTitle}" FontSize="20" Foreground="White"
HorizontalAlignment="Left" VerticalAlignment="Center" Margin="24,0,0,0"/>
Maybe wrapping the TextBlock inside a ViewBox scales the FontSize correctly也许将 TextBlock 包装在 ViewBox 中可以正确缩放 FontSize
<Viewbox Stretch="Uniform">
<TextBlock Text="{x:Static prop:Resources.AppTitle}" FontSize="20" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="24,0,0,0"/>
</Viewbox>
There is a msdn article about setting up different stretch properties How to: Apply Stretch Properties to the Contents of a Viewbox有一篇关于设置不同拉伸属性的 msdn 文章How to: Apply Stretch Properties to the Contents of a Viewbox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.