WPF/Silverlight XAML 拉伸文本大小以适合容器? [英] WPF/Silverlight XAML Stretch Text Size to Fit container?

查看:35
本文介绍了WPF/Silverlight XAML 拉伸文本大小以适合容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 WPF.

I've just started to play with WPF.

是否可以让 Label 的文本大小或 TextBlock 大小本身来填充其父容器?

Is it possible to have the size of the text of a Label or TextBlock size itself to fill it's parent container?

谢谢,标记

推荐答案

您可以使用 ViewBox 以可视化方式缩放某些内容以适合其容器.这里的其他解决方案有效,但它们只拉伸控件,而不是它的内容.ViewBox 将同时拉伸两者.

You can use a ViewBox to visually zoom something to fit within its container. The other solutions here work, but they only stretch the control, not its content. The ViewBox will stretch both.

<!-- Big grid, will stretch its children to fill itself -->
<Grid Width="1000" Height="1000">
 <!-- The button is stretched, but its text remains teeny tiny -->
 <Button>
  <!-- The viewbox will stretch its content 
  to fit the final size of the button -->
  <Viewbox
      Margin="4"
      VerticalAlignment="Stretch"
      Height="Auto">
      <!-- The textblock and its contents are 
      stretched to fill its parent -->
      <TextBlock
          Text="Bartenders" />
  </Viewbox>
 </Button>
</Grid>

这篇关于WPF/Silverlight XAML 拉伸文本大小以适合容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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