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

Mar*_*ark 28 size silverlight wpf text

我刚开始玩WPF.

是否可以使用Label或TextBlock大小的文本大小来填充它的父容器?

谢谢,马克

小智 47

您可以使用ViewBox直观地缩放某些内容以适合其容器.这里的其他解决方案有效,但它们只能扩展控制,而不是其内容.ViewBox将拉伸两者.

<!-- 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>
Run Code Online (Sandbox Code Playgroud)