微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WPF/Silverlight XAML拉伸文本大小以适应容器?

我刚刚开始玩WPF。

是否可能有一个Label或TextBlock大小的文本的大小本身填充它的父容器

谢谢,
标记

解决方法

您可以使用ViewBox来可视化缩放某物,以适应其容器。其他解决方在这里工作,但他们只是拉伸控制,而不是其内容。 ViewBox将拉伸两者。

<!-- Big grid,will stretch its children to fill itself -->
<Grid Width="1000" Height="1000">
 <!-- The button is @R_404_3785@,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 
      @R_404_3785@ to fill its parent -->
      <TextBlock
          Text="bartenders" />
  </ViewBox>
 </Button>
</Grid>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐